Created
September 21, 2016 00:34
-
-
Save JonathanGTH/b9af0d2583fcc75d1a24dbf5811aa09e to your computer and use it in GitHub Desktop.
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
def get_if_related_to(id, relationship) do | |
table("people") |> filter(lambda fn (person) -> | |
case relationship do | |
r when r in [:brother, :sister] -> | |
person[:siblings] |> contains(id) | |
r when r in [:mother, :father] -> | |
person[:children] |> contains(id) | |
r when r in [:son, :daughter] -> | |
table("people") | |
|> get(id) | |
|> get_field("children") | |
|> contains(person[:id]) | |
r when r in [:aunt, :uncle] -> | |
person[:siblings] | |
|> flat_map(fn sibling -> | |
sibling |> get_field("children") | |
end) |> contains(id) | |
end | |
end) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment