-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Higher-order function combinators
--   
--   Replacement for <a>composition</a> or `composition-extra`, exporting
--   everything in one module.
@package composition-prelude
@version 1.5.3.1

module Control.Composition

-- | As an example:
--   
--   <pre>
--   λ:&gt; ((*2) .* (+)) 1 3 4
--   16
--   </pre>
(.*) :: (c -> d) -> (a -> b -> c) -> a -> b -> d
infixr 8 .*
(.**) :: (d -> e) -> (a -> b -> c -> d) -> a -> b -> c -> e
infixr 8 .**
(.***) :: (e -> f) -> (a -> b -> c -> d -> e) -> a -> b -> c -> d -> f
infixr 8 .***
(.****) :: (f -> g) -> (a -> b -> c -> d -> e -> f) -> a -> b -> c -> d -> e -> g
infixr 8 .****

-- | Backwards function composition. This is a specialization of
--   <a>&lt;&amp;&gt;</a>.
(-.) :: (a -> b) -> (b -> c) -> a -> c

-- | The Oedipus combinator
(-.*) :: (b -> c) -> (a -> c -> d) -> a -> b -> d
infixr 8 -.*
(-.**) :: (c -> d) -> (a -> b -> d -> e) -> a -> b -> c -> e
infixr 8 -.**
(-.***) :: (d -> e) -> (a -> b -> c -> e -> f) -> a -> b -> c -> d -> f
infixr 8 -.***
(-.****) :: (e -> f) -> (a -> b -> c -> d -> f -> g) -> a -> b -> c -> d -> e -> g
infixr 8 -.****

-- | Right-to-left Kleisli composition of monads.
--   <tt>(<a>&gt;=&gt;</a>)</tt>, with the arguments flipped.
--   
--   Note how this operator resembles function composition
--   <tt>(<a>.</a>)</tt>:
--   
--   <pre>
--   (.)   ::            (b -&gt;   c) -&gt; (a -&gt;   b) -&gt; a -&gt;   c
--   (&lt;=&lt;) :: Monad m =&gt; (b -&gt; m c) -&gt; (a -&gt; m b) -&gt; a -&gt; m c
--   </pre>
(<=<) :: Monad m => b -> m c -> a -> m b -> a -> m c
infixr 1 <=<

-- | Left-to-right Kleisli composition of monads.
(>=>) :: Monad m => a -> m b -> b -> m c -> a -> m c
infixr 1 >=>

-- | A monadic version of <a>.*</a>. Compare <a>&lt;=&lt;</a>.
--   
--   As an example, one could use this to rewrite
--   
--   <pre>
--   \x y z -&gt; f (g x y z) z
--   </pre>
--   
--   to
--   
--   <pre>
--   f &lt;=*&lt; g
--   </pre>
(<=*<) :: Monad m => (c -> m d) -> (a -> b -> m c) -> a -> b -> m d

-- | The bleeding fish operator
(<=**<) :: Monad m => (d -> m e) -> (a -> b -> c -> m d) -> a -> b -> c -> m e

(>=**>) :: Monad m => (a -> b -> c -> m d) -> (d -> m e) -> a -> b -> c -> m e

-- | Compare <a>&gt;=&gt;</a>.
(>=*>) :: Monad m => (a -> b -> m c) -> (c -> m d) -> a -> b -> m d

(<-=*<) :: Monad m => (b -> m c) -> (a -> c -> m d) -> a -> b -> m d

(>-=*>) :: Monad m => (a -> c -> m d) -> (b -> m c) -> a -> b -> m d

(<-=**<) :: Monad m => (c -> m d) -> (a -> b -> d -> m e) -> a -> b -> c -> m e

(>-=**>) :: Monad m => (a -> b -> d -> m e) -> (c -> m d) -> a -> b -> c -> m e

-- | Can be used to rewrite
--   
--   <pre>
--   \g -&gt; f . g . h
--   </pre>
--   
--   to
--   
--   <pre>
--   between f h
--   </pre>
between :: (c -> d) -> (a -> b) -> (b -> c) -> a -> d
(~@~) :: (c -> d) -> (a -> b) -> (b -> c) -> a -> d
infixl 8 ~@~
betweenM :: Monad m => (c -> m d) -> (a -> m b) -> (b -> m c) -> a -> m d
(<~@~<) :: Monad m => (c -> m d) -> (a -> m b) -> (b -> m c) -> a -> m d
infixl 8 <~@~<

-- | Backwards function application
(-$) :: (a -> b -> c) -> b -> a -> c
infixl 8 -$
bisequence' :: (Traversable t, Applicative f) => t (a -> b -> f c) -> a -> b -> t (f c)
axe :: (Traversable t, Applicative f) => t (a -> f ()) -> a -> f ()
biaxe :: (Traversable t, Applicative f) => t (a -> b -> f ()) -> a -> b -> f ()
thread :: Foldable t => t (a -> a) -> a -> a
threadM :: (Monad m, Foldable t, Applicative m) => t (a -> m a) -> a -> m a
both :: (a -> b) -> (a, a) -> (b, b)

-- | <a>&amp;</a> is a reverse application operator. This provides
--   notational convenience. Its precedence is one higher than that of the
--   forward application operator <a>$</a>, which allows <a>&amp;</a> to be
--   nested in <a>$</a>.
--   
--   <pre>
--   &gt;&gt;&gt; 5 &amp; (+1) &amp; show
--   "6"
--   </pre>
(&) :: () => a -> a -> b -> b
infixl 1 &

-- | Flipped version of <a>&lt;$&gt;</a>.
--   
--   <pre>
--   (<a>&lt;&amp;&gt;</a>) = <a>flip</a> <a>fmap</a>
--   </pre>
--   
--   <h4><b>Examples</b></h4>
--   
--   Apply <tt>(+1)</tt> to a list, a <a>Just</a> and a <a>Right</a>:
--   
--   <pre>
--   &gt;&gt;&gt; Just 2 &lt;&amp;&gt; (+1)
--   Just 3
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; [1,2,3] &lt;&amp;&gt; (+1)
--   [2,3,4]
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; Right 3 &lt;&amp;&gt; (+1)
--   Right 4
--   </pre>
(<&>) :: Functor f => f a -> a -> b -> f b
infixl 1 <&>

-- | <tt><a>fix</a> f</tt> is the least fixed point of the function
--   <tt>f</tt>, i.e. the least defined <tt>x</tt> such that <tt>f x =
--   x</tt>.
--   
--   For example, we can write the factorial function using direct
--   recursion as
--   
--   <pre>
--   &gt;&gt;&gt; let fac n = if n &lt;= 1 then 1 else n * fac (n-1) in fac 5
--   120
--   </pre>
--   
--   This uses the fact that Haskell’s <tt>let</tt> introduces recursive
--   bindings. We can rewrite this definition using <a>fix</a>,
--   
--   <pre>
--   &gt;&gt;&gt; fix (\rec n -&gt; if n &lt;= 1 then 1 else n * rec (n-1)) 5
--   120
--   </pre>
--   
--   Instead of making a recursive call, we introduce a dummy parameter
--   <tt>rec</tt>; when used within <a>fix</a>, this parameter then refers
--   to <tt>fix'</tt> argument, hence the recursion is reintroduced.
fix :: () => a -> a -> a
on :: () => b -> b -> c -> a -> b -> a -> a -> c
infixl 0 `on`
