Does PureScript have a pipe operator?

1.5k views Asked by At

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?

2

There are 2 answers

0
Phil Freeman On BEST ANSWER

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)
1
Bellarmine Head On

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 |>