module Control.Composition
( -- ^ Postcomposition
(.*)
, (.**)
-- ^ Precomposition
, (-.)
, (-.*)
-- ^ Tuple helpers
, both
-- ^ Reexports from Control.Arrow
, (&&&)
, (***)
-- ^ Reexports from Control.Monad
, join
, (=<<)
, (>=>)
, (<=<)
-- ^ Reexports from base
, (&)
, fix
, on
) where
import Control.Arrow ((&&&), (***))
import Control.Monad (join, (<=<), (=<<), (>=>))
import Data.Function (fix, on, (&))
infixr 8 .*
infixr 8 -.*
{-weird' :: (b -> (c -> d)) -> (a -> (c -> b)) -> (a -> (c -> d))
weird' = (<=<)
weird :: (a -> (b -> c)) -> (b -> a) -> (b -> c)
weird = (=<<)-}
both :: (a -> b) -> (a, a) -> (b, b)
both = join (***)
-- | As an example:
--
-- > λ:> ((*2) .* (+)) 1 3 4
-- > 4
(.*) :: (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)
-- | 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)