Last active
May 20, 2016 04:34
-
-
Save fishtreesugar/0c650f83f2a7b469b66d10989eead7b8 to your computer and use it in GitHub Desktop.
elixir tricks
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
# Anonymous constructor | |
(&%{ok: &1}).(1) # => %{ok: 1} | |
Enum.map 1..5, &{&1, &1 * 2} # => [{1, 2}, {2, 4}, {3, 6}, {4, 8}, {5, 10}] | |
(&[1|&1]).(2) # => [1 | 2] | |
#macro | |
Enum.reduce items, %{}, fn item, map -> | |
Map.update(map, item, 1, & &1 + 1) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment