Hacker News new | ask | show | jobs
by jose_zap 417 days ago
Haskell has & which goes the other way:

    users
      & map validate
      & catMaybes
      & mapM persist
3 comments

Yes, `&` (reverse apply) is equivalent to `|>`, but it is interesting that there is no common operator for reversed compose `.`, so function compositions are still read right-to-left.

In my programming language, I added `.>` as a reverse-compose operator, so pipelines of function compositions can also be read uniformly left-to-right, e.g.

    process = map validate .> catMaybes .> mapM persist
Elm (written in Haskell) uses |> and <| for pipelining forwards and backwards, and function composition is >> and <<. These have made it into Haskell via nri-prelude https://hackage.haskell.org/package/nri-prelude (written by a company that uses a lot of Elm in order to make writing Haskell look more like writing Elm).

There is also https://hackage.haskell.org/package/flow which uses .> and <. for function composition.

EDIT: in no way do I want to claim the originality of these things in Elm or the Haskell package inspired by it. AFAIK |> came from F# but it could be miles earlier.

Maybe not common, but there’s Control.Arrow.(>>>)
Also you can (|>) = (&) (with an appropriate fixity declaration) to get

  users
    |> map validate
    |> catMaybes
    |> mapM persist
I guess I'm showing how long it's been since I was a student of Haskell then. Glad to see the addition!