composition-1.0.1.0: Combinators for unorthodox function composition

Safe HaskellSafe-Infered

Data.Composition

Contents

Description

This module is for convenience and demonstrative purposes more than it is for providing actual value. I do not recommend that you rely on this module for performance-sensitive code. Because this module is not based on Prelude's (.), some chances at optimization might be missed by your compiler.

Synopsis

Math

(∘) :: (b -> c) -> (a -> b) -> a -> cSource

The mathematical symbol for function composition.

Colons and dots

(.:) :: (c -> d) -> (a -> b -> c) -> a -> b -> dSource

Compose two functions. f .: g is similar to f . g except that g will be fed two arguments instead of one before handing its result to f.

This function is defined as

 (f .: g) x y = f (g x y)

Example usage:

 concatMap :: (a -> b) -> [a] -> [b]
 concatMap = concat .: map

Notice how two arguments (the function and the list) will be given to map before the result is passed to concat. This is equivalent to:

 concatMap f xs = concat (map f xs)

(.:.) :: (d -> e) -> (a -> b -> c -> d) -> a -> b -> c -> eSource

One compact pattern for composition operators is to count the dots after the first one, which begins with the common .:, and proceeds by first appending another . and then replacing it with :

(.::) :: (d -> e) -> (a -> a1 -> b -> c -> d) -> a -> a1 -> b -> c -> eSource

(.::.) :: (d -> e) -> (a -> a1 -> a2 -> b -> c -> d) -> a -> a1 -> a2 -> b -> c -> eSource

(.:::) :: (d -> e) -> (a -> a1 -> a2 -> a3 -> b -> c -> d) -> a -> a1 -> a2 -> a3 -> b -> c -> eSource

(.:::.) :: (d -> e) -> (a -> a1 -> a2 -> a3 -> a4 -> b -> c -> d) -> a -> a1 -> a2 -> a3 -> a4 -> b -> c -> eSource

(.::::) :: (d -> e) -> (a -> a1 -> a2 -> a3 -> a4 -> a5 -> b -> c -> d) -> a -> a1 -> a2 -> a3 -> a4 -> a5 -> b -> c -> eSource

(.::::.) :: (d -> e) -> (a -> a1 -> a2 -> a3 -> a4 -> a5 -> a6 -> b -> c -> d) -> a -> a1 -> a2 -> a3 -> a4 -> a5 -> a6 -> b -> c -> eSource

Asterisks

(.*) :: (c -> d) -> (a -> b -> c) -> a -> b -> dSource

Equivalent to .:

The pattern of appending asterisks is straightforward to extend to similar functions: (compose2 = .*, compose3 = .**, etc). However, .: has been commonly adopted amongst Haskellers, and the need for compose3 and beyond is rare in practice.

(.**) :: (d -> e) -> (a -> b -> c -> d) -> a -> b -> c -> eSource

(.***) :: (d -> e) -> (a -> a1 -> b -> c -> d) -> a -> a1 -> b -> c -> eSource

(.****) :: (d -> e) -> (a -> a1 -> a2 -> b -> c -> d) -> a -> a1 -> a2 -> b -> c -> eSource

(.*****) :: (d -> e) -> (a -> a1 -> a2 -> a3 -> b -> c -> d) -> a -> a1 -> a2 -> a3 -> b -> c -> eSource

(.******) :: (d -> e) -> (a -> a1 -> a2 -> a3 -> a4 -> b -> c -> d) -> a -> a1 -> a2 -> a3 -> a4 -> b -> c -> eSource

(.*******) :: (d -> e) -> (a -> a1 -> a2 -> a3 -> a4 -> a5 -> b -> c -> d) -> a -> a1 -> a2 -> a3 -> a4 -> a5 -> b -> c -> eSource

(.********) :: (d -> e) -> (a -> a1 -> a2 -> a3 -> a4 -> a5 -> a6 -> b -> c -> d) -> a -> a1 -> a2 -> a3 -> a4 -> a5 -> a6 -> b -> c -> eSource

composeN

compose1 :: (b -> c) -> (a -> b) -> a -> cSource

composeN f g means give g N inputs and then pass its result to f.

compose2 :: (c -> d) -> (a -> b -> c) -> a -> b -> dSource

compose3 :: (d -> e) -> (a -> b -> c -> d) -> a -> b -> c -> eSource

compose4 :: (d -> e) -> (a -> a1 -> b -> c -> d) -> a -> a1 -> b -> c -> eSource

compose5 :: (d -> e) -> (a -> a1 -> a2 -> b -> c -> d) -> a -> a1 -> a2 -> b -> c -> eSource

compose6 :: (d -> e) -> (a -> a1 -> a2 -> a3 -> b -> c -> d) -> a -> a1 -> a2 -> a3 -> b -> c -> eSource

compose7 :: (d -> e) -> (a -> a1 -> a2 -> a3 -> a4 -> b -> c -> d) -> a -> a1 -> a2 -> a3 -> a4 -> b -> c -> eSource

compose8 :: (d -> e) -> (a -> a1 -> a2 -> a3 -> a4 -> a5 -> b -> c -> d) -> a -> a1 -> a2 -> a3 -> a4 -> a5 -> b -> c -> eSource

compose9 :: (d -> e) -> (a -> a1 -> a2 -> a3 -> a4 -> a5 -> a6 -> b -> c -> d) -> a -> a1 -> a2 -> a3 -> a4 -> a5 -> a6 -> b -> c -> eSource