composition-prelude-1.3.0.8: Higher-order function combinators

Safe HaskellNone
LanguageHaskell2010

Control.Composition

Contents

Synopsis

Postcomposition

(.*) :: (c -> d) -> (a -> b -> c) -> a -> b -> d infixr 8 Source #

As an example:

λ:> ((*2) .* (+)) 1 3 4
16

(.**) :: (d -> e) -> (a -> b -> c -> d) -> a -> b -> c -> e infixr 8 Source #

(.***) :: (e -> f) -> (a -> b -> c -> d -> e) -> a -> b -> c -> d -> f infixr 8 Source #

(.****) :: (f -> g) -> (a -> b -> c -> d -> e -> f) -> a -> b -> c -> d -> e -> g infixr 8 Source #

Precomposition

(-.) :: (a -> b) -> (b -> c) -> a -> c Source #

Backwards function composition

(-.*) :: (b -> c) -> (a -> c -> d) -> a -> b -> d infixr 8 Source #

The Oedipus combinator

(-.**) :: (c -> d) -> (a -> b -> d -> e) -> a -> b -> c -> e infixr 8 Source #

(-.***) :: (d -> e) -> (a -> b -> c -> e -> f) -> a -> b -> c -> d -> f infixr 8 Source #

(-.****) :: (e -> f) -> (a -> b -> c -> d -> f -> g) -> a -> b -> c -> d -> e -> g infixr 8 Source #

Fancy function application

(-$) :: (a -> b -> c) -> b -> a -> c infixl 8 Source #

Backwards function

Monadic helpers

bisequence' :: (Traversable t, Monad m) => t (a -> b -> m c) -> a -> b -> t (m c) Source #

Monadic actions

axe :: (Traversable t, Monad m) => t (a -> m ()) -> a -> m () Source #

biaxe :: (Traversable t, Monad m) => t (a -> b -> m ()) -> a -> b -> m () Source #

Composition with lists of functions

thread :: [a -> a] -> a -> a Source #

Tuple helpers

both :: (a -> b) -> (a, a) -> (b, b) Source #

Functor helpers

(<&>) :: Functor f => f a -> (a -> b) -> f b infixl 1 Source #

Reexports from base

(&) :: a -> (a -> b) -> b infixl 1 #

& is a reverse application operator. This provides notational convenience. Its precedence is one higher than that of the forward application operator $, which allows & to be nested in $.

Since: 4.8.0.0

fix :: (a -> a) -> a #

fix f is the least fixed point of the function f, i.e. the least defined x such that f x = x.

on :: (b -> b -> c) -> (a -> b) -> a -> a -> c infixl 0 #

(*) `on` f = \x y -> f x * f y.

Typical usage: sortBy (compare `on` fst).

Algebraic properties:

  • (*) `on` id = (*) (if (*) ∉ {⊥, const ⊥})
  • ((*) `on` f) `on` g = (*) `on` (f . g)
  • flip on f . flip on g = flip on (g . f)

ap :: Monad m => m (a -> b) -> m a -> m b #

In many situations, the liftM operations can be replaced by uses of ap, which promotes function application.

      return f `ap` x1 `ap` ... `ap` xn

is equivalent to

      liftMn f x1 x2 ... xn

bool :: a -> a -> Bool -> a #

Case analysis for the Bool type. bool x y p evaluates to x when p is False, and evaluates to y when p is True.

This is equivalent to if p then y else x; that is, one can think of it as an if-then-else construct with its arguments reordered.

Examples

Basic usage:

>>> bool "foo" "bar" True
"bar"
>>> bool "foo" "bar" False
"foo"

Confirm that bool x y p and if p then y else x are equivalent:

>>> let p = True; x = "bar"; y = "foo"
>>> bool x y p == if p then y else x
True
>>> let p = False
>>> bool x y p == if p then y else x
True

Since: 4.7.0.0