Created
September 5, 2018 08:57
-
-
Save dsignr/6c32ebeb83ba54c05e161c5a874c34a8 to your computer and use it in GitHub Desktop.
Dynamic way to access an element's attributes in Elixir
This file contains hidden or 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
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