Skip to content

Instantly share code, notes, and snippets.

@fishtreesugar
Last active May 20, 2016 04:34
Show Gist options
  • Save fishtreesugar/0c650f83f2a7b469b66d10989eead7b8 to your computer and use it in GitHub Desktop.
Save fishtreesugar/0c650f83f2a7b469b66d10989eead7b8 to your computer and use it in GitHub Desktop.
elixir tricks
# 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