Coming from the F# world, I am used to using |>
to pipe data into functions:
[1..10] |> List.filter (fun n -> n % 2 = 0) |> List.map (fun n -> n * n);
I assume that PureScript, being inspired by Haskell, has something similar.
How do I use the pipe operator in PureScript?
Yes, you can use #
which is defined in Prelude.
Here is your example, rewritten using #
:
http://try.purescript.org/?gist=0448c53ae7dc92278ca7c2bb3743832d&backend=core
module Main where
import Prelude
import Data.List ((..))
import Data.List as List
example = 1..10 # List.filter (\n -> n `mod` 2 == 0)
# map (\n -> n * n)
Here's one way to define the |>
operator for use in PureScript; it's defined in exactly the same way as #
- i.e. with the same precedence and associativity:-
pipeForwards :: forall a b. a -> (a -> b) -> b
pipeForwards x f = f x
infixl 1 pipeForwards as |>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With