Does PureScript have a pipe operator?

From the world of F #, I use |>to transfer data to functions:

[1..10] |> List.filter (fun n -> n % 2 = 0) |> List.map (fun n -> n * n);

I guess PureScript, being inspired by Haskell, has something similar.

How to use pipe operator in PureScript?

+4
source share
2 answers

Yes, you can use #one that is defined in Prelude.

Here is your example rewritten with #:

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)
+6
source

Here is one way to define a statement |>for use in PureScript; it is defined in exactly the same way as #- that is, with the same priority and associativity: -

pipeForwards :: forall a b. a -> (a -> b) -> b
pipeForwards x f = f x
infixl 1 pipeForwards as |>
+1
source

Source: https://habr.com/ru/post/1664348/


All Articles