Not a language, but a language feature: in Elixir, there’s a capture operator & that will wrap functions in an anonymous function and also can be used to refer to the nth argument of a function. For example:
Scala also has _, which in _ + 1 is an alias for x => x + 1, or in the case of f(_), is an alias for x => f(x). Oleg Kiselyov has an interesting take on it.
I’m not that familiar with Elixir (only having done a few basic distributed algorithms in it), but this feature has piqued my interest even further in the language, thanks for the handy tip!
Not a language, but a language feature: in Elixir, there’s a capture operator
&that will wrap functions in an anonymous function and also can be used to refer to the nth argument of a function. For example:is replaced by
This helps avoid naming arguments unnecessarily.
Read more
This is one of the features inspired by Clojure. In Clojure,
#(foo %)is short for (fn [x] (foo x))You also have
%1,%2etc. in Clojure.There’s also the pipe operator |> which passes the result of the expression on the left side as the first argument of the function on the right.
https://elixirschool.com/en/lessons/basics/pipe-operator/
Scala also has
_, which in_ + 1is an alias forx => x + 1, or in the case off(_), is an alias forx => f(x). Oleg Kiselyov has an interesting take on it.I’m not that familiar with Elixir (only having done a few basic distributed algorithms in it), but this feature has piqued my interest even further in the language, thanks for the handy tip!