Writing Haskell programs I found myself in need of an operator like this.
(|>) :: a -> (a -> b) -> b
(|>) = flip ($)
infixl 0 |>
I think it is useful when glueing many functions together.
tText cs = someFun cs |>
lines |>
map (drop 4) |>
reverse
I prefer it over .
because with |>
the order in which the functions are applied is the same as the order in which the functions are written.
tText' cs = reverse .
map (drop 4) .
lines .
someFun $ cs
Question is: is this (|>
) something that already exists in the Prelude
/ some other basic library? Reimplementing simple stuff is something silly which I would like to avoid.
A Hoogle search did not help. Closest thing I found was >>>
(Arrows), but it seems an overkill.
>>>
does. There was another SO question about why F# uses|>
where Haskell uses.
and$
, which is pretty relevant. (Note also, just for fun, that with.
or>>>
, you can write your function point-free:tText = reverse . map (drop 4) . lines . someFun
, ortText = someFun >>> lines >>> map (drop 4) >>> reverse
.)do
notation is always "forwards".tText cs = ($ cs) $ someFun >>> lines >>> map (drop 4) >>> reverse