flow-1.0.0: Functions and operators for more understandable Haskell

Safe HaskellSafe-Inferred
LanguageHaskell98

Flow

Contents

Description

Flow provides functions and operators for writing more understandable Haskell.

Flow does not export anything that conflicts with the Prelude. The recommended way to use Flow is to import it unqualified.

>>> import Flow

Synopsis

Function application

apply :: a -> (a -> b) -> b Source

apply x f == f x

Function application. This is like the $ operator.

>>> apply False not
True

Using this function with many arguments is cumbersome. Use |> or <| instead.

>>> False `apply` not `apply` fromEnum
1

This function usually isn't necessary since apply x f is the same as f x. However it can come in handy when working with higher-order functions.

>>> map (apply False) [not, id]
[True,False]

(|>) :: a -> (a -> b) -> b infixl 0 Source

(x |> f) == f x

Left-associative apply operator. This is like a flipped version of the $ operator. Read it as "apply forward" or "pipe into".

>>> False |> not
True

Since this operator has such low precedence, it can be used to remove parentheses from complicated expressions.

>>> False |> not |> fromEnum
1

This operator can be used with higher-order functions, but apply might be clearer.

>>> map (False |>) [not, id]
[True,False]

(<|) :: (a -> b) -> a -> b infixr 0 Source

(f <| x) == f x

Right-associative apply operator. This is like the $ operator. Read it as "apply backward" or "pipe from".

>>> not <| False
True

This operator can be used to remove parentheses from complicated expressions because of its low precedence.

>>> fromEnum <| not <| False
1

With higher-order functions, this operator is a clearer alternative to flip apply.

>>> map (<| False) [not, id]
[True,False]

Function composition

compose :: (a -> b) -> (b -> c) -> a -> c Source

compose f g x == g (f x)

Function composition. This is like the . operator.

>>> (compose not fromEnum) False
1

Composing many functions together quickly becomes unwieldy. Use .> or <. instead.

>>> (not `compose` fromEnum `compose` succ) False
2

(.>) :: (a -> b) -> (b -> c) -> a -> c infixl 9 Source

(f .> g) x == g (f x)

Left-associative compose operator. This is like a flipped version of the . operator. Read it as "compose forward" or "and then".

>>> (not .> fromEnum) False
1

Thanks to its high precedence, composing many functions together is easy.

>>> (not .> fromEnum .> succ) False
2

(<.) :: (b -> c) -> (a -> b) -> a -> c infixr 9 Source

(g <. f) x == g (f x)

Right-associative compose operator. This is like the . operator. Read it as "compose backward" or "but first".

>>> (fromEnum <. not) False
1

Composing many functions together is easy thanks to its high precedence.

>>> (succ <. fromEnum <. not) False
2

Strict function application

apply' :: a -> (a -> b) -> b Source

apply' x f == seq x (f x)

Strict function application. This is like the $! operator.

>>> apply' undefined (const False)
*** Exception: Prelude.undefined

(!>) :: a -> (a -> b) -> b infixl 0 Source

(x !> f) == seq x (f x)

Left-associative apply' operator. This is like a flipped version of the $! operator.

>>> undefined !> const False
*** Exception: Prelude.undefined

(<!) :: (a -> b) -> a -> b infixr 0 Source

(f <! x) == seq x (f x)

Right-associative apply' operator. This is like the $! operator.

>>> const False <! undefined
*** Exception: Prelude.undefined