module Control.Composition
( -- ^ Postcomposition
(.*)
, (.**)
, (.***)
-- ^ Precomposition
, (-.)
, (-.*)
-- ^ Tuple helpers
, both
-- ^ Reexports from Control.Arrow
, (&&&)
, (***)
-- ^ Reexports from Control.Monad
, join
, (=<<)
, (>=>)
, (<=<)
-- ^ Reexports from base
, (&)
, fix
, on
, ap
) where
import Control.Arrow ((&&&), (***))
import Control.Monad (ap, join, (<=<), (=<<), (>=>))
import Data.Function (fix, on, (&))
infixr 8 .*
infixr 8 -.*
{-fish' :: (a -> c -> b) -> (b -> c -> c) -> a -> c -> c
fish' f g x y = g (f x y) y
fish :: (a -> c -> b) -> (b -> c -> c) -> (a -> c -> c)
fish = (>=>)-}
both :: (a -> b) -> (a, a) -> (b, b)
both = join (***)
-- | As an example:
--
-- > λ:> ((*2) .* (+)) 1 3 4
-- > 16
(.*) :: (c -> d) -> (a -> b -> c) -> a -> b -> d
(.*) f g x y = f (g x y)
(.**) :: (d -> e) -> (a -> b -> c -> d) -> a -> b -> c -> e
(.**) f g x y z = f (g x y z)
(.***) :: (e -> f) -> (a -> b -> c -> d -> e) -> a -> b -> c -> d -> f
(.***) f g w x y z = f (g w x y z)
-- | The Oedipus combinator
(-.*) :: (b -> c) -> (a -> c -> d) -> a -> b -> d
(-.*) f g x y = g x (f y)
-- | Backwards function composition
(-.) :: (a -> b) -> (b -> c) -> a -> c
(-.) f g x = g (f x)