Elixir: Capture Operator: &

Using ‘&’ as a Capture Operator

nick3499
1 min readJul 16, 2017
capture_oper.ex

IEx CLI Examples

In the code example below, the function was specified using & as a capture operator.

Capture Operator

iex(1)> Hof.tripler(6, &(20 * &1))
360

The capture operator example above becomes an economical alternative to the higher-order function example below:

Higher-Order Function

iex(1)> Hof.tripler(6, (fn(value) -> 20 * value end))
360

--

--

nick3499
nick3499

Written by nick3499

coder of JavaScript and Python

No responses yet