Skip to content

Instantly share code, notes, and snippets.

@dsignr
Created September 5, 2018 08:57
Show Gist options
  • Save dsignr/6c32ebeb83ba54c05e161c5a874c34a8 to your computer and use it in GitHub Desktop.
Save dsignr/6c32ebeb83ba54c05e161c5a874c34a8 to your computer and use it in GitHub Desktop.
Dynamic way to access an element's attributes in Elixir
defp find_in_combinations(combinations, element) do
Enum.reduce(combinations, [], fn(c, acc) ->
# A dynamic way to access c.element (Eg. c.engine)
if Map.get(c, element) do
acc ++ [Map.get(c, element)]
else
acc
end
end)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment