Elixir: Support << and >> function composition operators

Created on 10 Jan 2013  路  4Comments  路  Source: elixir-lang/elixir

See:

Should be a relatively simple compiler/kernel hack to support those.

We probably can't use << and >> since they would conflict with binary syntax, though.

Most helpful comment

I would love to see things in Function module like complement, juxt, comp, partial (not sure if this is necessary, but it can make functional programmer look nicer) and much more to make elixir prettier as functional language :) Any updates on that?

All 4 comments

Indeed, we can't use << nor >>.

For instance, Clojure provides a comp macro/function: http://clojuredocs.org/clojure_core/1.2.0/clojure.core/comp

I am also interested in examples where such would be useful. Since we don't have rest args and functions need to be identified by name and arity, it seems that partial application and the pipeline operator covers most of the cases more elegantly:

Enum.map paths, &1 |> File.expand_path |> File.basename

Compared to:

Enum.map paths, comp File.expand_path(&1), File.basename(&1)

Well, comp would help in cases the first function expects more than one arg. However, since we have to specify the number of args for each function, I don't see much gain.

I am closing this (preparing for release). I am open for the inclusion of compose though, maybe it is time to start filling in the Function module.

I would love to see things in Function module like complement, juxt, comp, partial (not sure if this is necessary, but it can make functional programmer look nicer) and much more to make elixir prettier as functional language :) Any updates on that?

Was this page helpful?
0 / 5 - 0 ratings