Seems you would like to have currying in Elixir. It's not possible in general way on BEAM, but I had fun with doing it some years ago: https://github.com/romul/utils/blob/master/lib/utils/functions.ex#L49
So, you could use it like Enum.map(rcarry(&Tuple.append/2, 42)) вторник, 2 июля 2019 г., 19:52:51 UTC+3 пользователь Rich Morin написал: > > I enjoyed reading "[elixir-core:8881] [Proposal] identity function" and > the > ensuing discussion. It strikes me that some simple extensions to Elixir's > function capture syntax might: > > - clean up the appearance of function captures > - make existing functions more generally useful > - reduce the need for special-purpose lambdas > > When a captured function is being used as an argument, it may be possible > to infer its arity. So, maybe we can leave this out: > > Enum.map(&id) > Enum.sort_by(&String.downcase) > > Many named functions take multiple arguments, so they can't be used in > function captures. Allowing arguments could extend their reach: > > Enum.sort_by(&elem(1)) # sort by the 2nd element > Enum.map(&Tuple.append(42)) # append 42 to each tuple > > On a loosely related note, Clojure gets a lot of mileage out of some > higher-order abstractions (eg, seqs). There may be opportunities for > Elixir to follow their lead. For example, some Enum and List functions > might be applicable to Tuples. Similarly, String functions such as > downcase/1 could be extended to accept atoms, etc. > > (ducks) > > -r > > -- You received this message because you are subscribed to the Google Groups "elixir-lang-core" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/1eb8c127-5ec1-4d6b-a142-98610b90952d%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
