Last active
April 10, 2018 03:19
-
-
Save elbrujohalcon/5c81757a1c94a4200ac1bda85786c35d to your computer and use it in GitHub Desktop.
In My Life (by The Beatles)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(in). | |
-author(john). | |
-author(paul). | |
-author(george). | |
-author(ringo). | |
-export([my_life/1]). | |
my_life(NewPlaces) -> | |
Places = db:get_all(places), | |
UpdatedPlaces = | |
[ NewPlace | |
|| NewPlace <- NewPlaces | |
, lists:member(NewPlace, Places) | |
], | |
lists:foreach( | |
fun(Place) -> | |
db:insert(places, Place) | |
end, UpdatedPlaces), | |
DeletedPlaces = | |
[ Place | |
|| Place <- Places | |
, not lists:member(Place, NewPlaces) | |
], | |
db:delete(places, DeletedPlaces), | |
Moments = | |
[ Moment | |
|| Place <- Places | |
, Moment <- places:moments(Place) | |
], | |
People = | |
[ Person | |
|| Moment <- Moments | |
, Person <- moments:lovers(Moment) ++ moments:friends(Moment) | |
], | |
{Dead, Living} = | |
lists:partition( | |
fun person:is_dead/1, People), | |
lists:foreach( | |
fun person:love/1, Dead ++ Living), | |
You = db:get_first(people), | |
[] = | |
[ Person | |
|| Person <- People | |
, person:comparable(Person, You) | |
], | |
ok = love:update(), | |
UpdatedMemories = | |
[ moments:meaning(Moment, null) | |
|| Moment <- Moments | |
], | |
db:update(moments, UpdatedMemories), | |
my_life(You, People, UpdatedMemories). | |
my_life(You, People, Things) -> | |
case rand:uniform(5) of | |
1 -> | |
timer:sleep(rand:uniform(100) + 100), | |
person:think_about(People); | |
2 -> | |
timer:sleep(rand:uniform(100) + 100), | |
moments:think_about(Things); | |
_ -> | |
dont_stop_now | |
end, | |
person:love(You), | |
my_life(You, People, Things). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment