Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save binarytemple/c937f5310d0cd0f365f354b6462f33be to your computer and use it in GitHub Desktop.
Save binarytemple/c937f5310d0cd0f365f354b6462f33be to your computer and use it in GitHub Desktop.
elixir anonymous function - wrapping case statement - arguments as single tuple
iex(9)> 
add = fn x ->
case x do
{x,y,f} -> f.(x,y)
{x,y} -> x + y 
_ -> raise("bad match")
end
end
#Function<6.54118792/1 in :erl_eval.expr/5>
iex(10)> add.({1,1})
2
iex(11)> add.({1,1,fn x,y -> x + y end})
2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment