Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Functions

2_named_functions.livemd

Functions

# import IEx.Helpers

Named Functions

IO.puts("hello")
# side effect, print "hello"
hello
:ok

Capture

function = &IO.inspect/1
&IO.inspect/1
i(function)
error: undefined function i/1 (there is no such import)
  #cell:u3zksoroaaguytlpbz74g7litccurzv7:1

As value

Enum.each(1..8, function)
1
2
3
4
5
6
7
8
:ok

Erlang

:random.uniform(2)
1
random_float_fn = &:random.uniform/0
&:random.uniform/0
random_float_fn.()
0.7230402056221108
Stream.repeatedly(random_float_fn) |> Enum.take(10)
[0.94581636451987, 0.5014907142064751, 0.311326754804393, 0.597447524783298, 0.915656206971831,
 0.6669572934854013, 0.47712105608919275, 0.5965100813402789, 0.14210821770124227,
 0.20944855618709624]
import IEx.Helpers, only: [i: 1]
IEx.Helpers
i(&IO.puts/1)
Term
  &IO.puts/1
Data type
  Function
Type
  external
Arity
  1
Implemented protocols
  Enumerable, IEx.Info, Inspect