git / email
index

Partially applied functions in Elixir

Thanks to the capture operator it’s easy to create partially applied functions in Elixir:

iex> sum = fn (a, b) -> a + b end
iex> sum.(1, 2)
3
iex> add42 = &sum.(&1, 42)
iex> add42.(3)
45
iex> greet = &IO.puts("Hello " <> &1 <> "!")
iex> greet.("Marvin")
Hello Marvin!
:ok