6 ms·
Haskell has & which goes the other way: users & map validate & catMaybes & mapM persist
by jose_zap 1y ago
Haskell has & which goes the other way:
users
& map validate
& catMaybes
& mapM persist
- Symmetry 1y agoI guess I'm showing how long it's been since I was a student of Haskell then. Glad to see the addition!
- taolson 1y agoYes, `&` (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
- 1-more 1y agoElm (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 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 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.
- shadytrees 1y agoMaybe not common, but there’s Control.Arrow.(>>>)
- lgas 1y agoAlso you can (|>) = (&) (with an appropriate fixity declaration) to get users |> map validate |> catMaybes |> mapM persist