Welcome to the forum!
FYI:
Good day everyone!
I am using Enum.reduce/3 (https://hexdocs.pm/elixir/1.9.0-rc.0/Enum.html#reduce/3 ) function quite often and I am regularly wondering why are the arguments for reducing function x, acc instead of acc, x.
Almost all functions in Elixir are in the form of Module.function(subject_of_change, change_argument). For example MapSet.put/2 or List.delete/2. Thanks to this, we can write code like:
changeset
|> cast(params, [ ... ])
|> validate_required([ ... ])
|> unique_constraint( ..…
That topic does come up regularly but because on the BEAM different functions can have the same name as long as the arity differs, creating Haskell-style “compile time notational currying” is basically out of the question anyway.
(In Bucklescript, which supports curried functions, parameter position was an ardently discussed topic ).
Today I realized that it would be possible to implement currying-capability in Elixir, using some clever anonymous function creation. (‘continuation-style currying’).
There was already a library called curry, which required you to define your to-be-curried functions using a special macro. And it would then define 255(the max. arity in Elixir) different function heads for it.
Currying does not do that. Instead, when yo u call curry, the passed function is wrapped in an anonymous function accept…
Elm has pipe operator like Elixir does. I read on reddit that OCaml and F# also have pipe operators.
I’m curious if it was Elixir which introduced the pipe operator and other languages copied it, or it was some other language which introduced the idea of pipe operator?
TL;DNR:
The first argument position is targeted by Kernel.|>/2
- this effectively puts the first argument position in the role that is typically filled by the last argument position in other (curried) FP languages.
The last argument position often accepts a keyword list of optional values (defaulting to an empty list) - syntax sugar makes the enclosing (list) square brackets optional - the function pretends to be variadic.
5 Likes