Search
Items tagged with: function
I had no idea functions could be passed around as variables in Elixir
I know this is a basic feature of most languages, but I’ve been working around it this whole time because I thought it wasn’t possible.
iex(1)> f = fn x -> x*x end
<a class="hashtag" data-tag="function" href="https://gleasonator.com/tag/function">#Function</a><44.79398840/1 in :erl_eval.expr/5>
iex(2)> is_function(f)
true
iex(3)> f.(4)
16
I know this is a basic feature of most languages, but I’ve been working around it this whole time because I thought it wasn’t possible.