Skip to content

Instantly share code, notes, and snippets.

@JonathanGTH
Created September 21, 2016 00:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonathanGTH/b9af0d2583fcc75d1a24dbf5811aa09e to your computer and use it in GitHub Desktop.
Save JonathanGTH/b9af0d2583fcc75d1a24dbf5811aa09e to your computer and use it in GitHub Desktop.
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