    {-|

    Element-agnostic grouping utilities for @pipes@

    See "Pipes.Group.Tutorial" for an extended tutorial

    Some type signatures below refer to the aliases below, which are not used in
    this library, but are included to simplify the documentation.

    @
    type Groups         a m x = 'FreeT' ('Producer' a m) m x
    type Splitter       a m x = 'Producer' a m x -> Groups a m x
    type Transformation a m x = Groups a m x -> Groups a m x
    type Joiner         a m x = Groups a m x -> 'Producer' a m x
    @
    -}

    {-# LANGUAGE RankNTypes #-}

    module Pipes.Group (
        -- * Lenses
        groups,
        groupsBy,
        groupsBy',
        chunksOf,

        -- * Transformations
        takes,
        takes',
        drops,
        maps,
        individually,

        -- * Joiners
        concats,
        intercalates,

        -- * Folds
        -- $folds
        folds,
        foldsM,

        -- * Re-exports
        -- $reexports
        module Control.Monad.Trans.Class,
        module Control.Monad.Trans.Free,
        module Pipes
        ) where

    import Control.Monad.Trans.Class (lift)
    import Control.Monad.Trans.Free (FreeF(Pure, Free), FreeT(FreeT, runFreeT))
    import qualified Control.Monad.Trans.Free as F
    import Data.Functor.Constant (Constant(Constant, getConstant))
    import Data.Functor.Identity (Identity(Identity, runIdentity))
    import Pipes (Producer, yield, next)
    import Pipes.Parse (span, splitAt)
    import qualified Pipes as P

    import Prelude hiding (span, splitAt)

    type Lens a' a b' b = forall f . Functor f => (b' -> f b) -> (a' -> f a)
    type Setter a' a b' b = (b' -> Identity b) -> (a' -> Identity a)

    (^.) :: a -> ((b -> Constant b b) -> (a -> Constant b a)) -> b
    a
    a ^. :: forall a b. a -> ((b -> Constant b b) -> a -> Constant b a) -> b
    ^. (b -> Constant b b) -> a -> Constant b a
    lens = Constant b a -> b
    forall {k} a (b :: k). Constant a b -> a
    getConstant ((b -> Constant b b) -> a -> Constant b a
    lens b -> Constant b b
    forall {k} a (b :: k). a -> Constant a b
    Constant a
    a)

    {-| 'groupsBy' splits a 'Producer' into a 'FreeT' of 'Producer's grouped using
        the given equality predicate

    @
          groupsBy p  :: Monad m => Lens' ('Producer' a m x) (Groups a m x)
    view (groupsBy p) :: Monad m => Splitter a m x
    set  (groupsBy p) :: Monad m => Groups a m x -> 'Producer' a m x -> 'Producer' a m x
    over (groupsBy p) :: Monad m => Transformation a m x -> 'Producer' a m x -> 'Producer' a m x
    @

    >>> import Lens.Family (view)
    >>> import Pipes (yield, each)
    >>> import Pipes.Prelude (toList)
    >>> (toList . intercalates (yield '|') . view (groupsBy (==))) (each "12233345")
    "1|22|333|4|5"
    -}
    groupsBy
        :: Monad m
        => (a' -> a' -> Bool)
        -> Lens (Producer a' m x) (Producer a m x) (FreeT (Producer a' m) m x) (FreeT (Producer a m) m x)
    groupsBy :: forall (m :: * -> *) a' x a.
    Monad m =>
    (a' -> a' -> Bool)
    -> Lens
         (Producer a' m x)
         (Producer a m x)
         (FreeT (Producer a' m) m x)
         (FreeT (Producer a m) m x)
    groupsBy a' -> a' -> Bool
    equals FreeT (Producer a' m) m x -> f (FreeT (Producer a m) m x)
    k Producer a' m x
    p0 = (FreeT (Producer a m) m x -> Producer a m x)
    -> f (FreeT (Producer a m) m x) -> f (Producer a m x)
    forall a b. (a -> b) -> f a -> f b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap FreeT (Producer a m) m x -> Producer a m x
    forall (m :: * -> *) a x.
    Monad m =>
    FreeT (Producer a m) m x -> Producer a m x
    concats (FreeT (Producer a' m) m x -> f (FreeT (Producer a m) m x)
    k (Producer a' m x -> FreeT (Producer a' m) m x
    forall {m :: * -> *} {a}.
    Monad m =>
    Producer a' m a -> FreeT (Proxy X () () a' m) m a
    _groupsBy Producer a' m x
    p0))
      where
    --  _groupsBy :: Monad m => Producer a m r -> FreeT (Producer a m) m r
        _groupsBy :: Producer a' m a -> FreeT (Proxy X () () a' m) m a
    _groupsBy Producer a' m a
    p = m (FreeF (Proxy X () () a' m) a (FreeT (Proxy X () () a' m) m a))
    -> FreeT (Proxy X () () a' m) m a
    forall (f :: * -> *) (m :: * -> *) a.
    m (FreeF f a (FreeT f m a)) -> FreeT f m a
    FreeT (m (FreeF (Proxy X () () a' m) a (FreeT (Proxy X () () a' m) m a))
     -> FreeT (Proxy X () () a' m) m a)
    -> m (FreeF
            (Proxy X () () a' m) a (FreeT (Proxy X () () a' m) m a))
    -> FreeT (Proxy X () () a' m) m a
    forall a b. (a -> b) -> a -> b
    $ do
            Either a (a', Producer a' m a)
    x <- Producer a' m a -> m (Either a (a', Producer a' m a))
    forall (m :: * -> *) a r.
    Monad m =>
    Producer a m r -> m (Either r (a, Producer a m r))
    next Producer a' m a
    p
            FreeF (Proxy X () () a' m) a (FreeT (Proxy X () () a' m) m a)
    -> m (FreeF
            (Proxy X () () a' m) a (FreeT (Proxy X () () a' m) m a))
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (FreeF (Proxy X () () a' m) a (FreeT (Proxy X () () a' m) m a)
     -> m (FreeF
             (Proxy X () () a' m) a (FreeT (Proxy X () () a' m) m a)))
    -> FreeF (Proxy X () () a' m) a (FreeT (Proxy X () () a' m) m a)
    -> m (FreeF
            (Proxy X () () a' m) a (FreeT (Proxy X () () a' m) m a))
    forall a b. (a -> b) -> a -> b
    $ case Either a (a', Producer a' m a)
    x of
                Left   a
    r      -> a -> FreeF (Proxy X () () a' m) a (FreeT (Proxy X () () a' m) m a)
    forall (f :: * -> *) a b. a -> FreeF f a b
    Pure a
    r
                Right (a'
    a, Producer a' m a
    p') -> Proxy X () () a' m (FreeT (Proxy X () () a' m) m a)
    -> FreeF (Proxy X () () a' m) a (FreeT (Proxy X () () a' m) m a)
    forall (f :: * -> *) a b. f b -> FreeF f a b
    Free (Proxy X () () a' m (FreeT (Proxy X () () a' m) m a)
     -> FreeF (Proxy X () () a' m) a (FreeT (Proxy X () () a' m) m a))
    -> Proxy X () () a' m (FreeT (Proxy X () () a' m) m a)
    -> FreeF (Proxy X () () a' m) a (FreeT (Proxy X () () a' m) m a)
    forall a b. (a -> b) -> a -> b
    $
                    (Producer a' m a -> FreeT (Proxy X () () a' m) m a)
    -> Proxy X () () a' m (Producer a' m a)
    -> Proxy X () () a' m (FreeT (Proxy X () () a' m) m a)
    forall a b.
    (a -> b) -> Proxy X () () a' m a -> Proxy X () () a' m b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap Producer a' m a -> FreeT (Proxy X () () a' m) m a
    _groupsBy (a' -> Proxy X () () a' m ()
    forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
    yield a'
    a Proxy X () () a' m ()
    -> Proxy X () () a' m (Producer a' m a)
    -> Proxy X () () a' m (Producer a' m a)
    forall a b.
    Proxy X () () a' m a
    -> Proxy X () () a' m b -> Proxy X () () a' m b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> (Producer a' m a
    p' Producer a' m a
    -> ((Proxy X () () a' m (Producer a' m a)
         -> Constant
              (Proxy X () () a' m (Producer a' m a))
              (Proxy X () () a' m (Producer a' m a)))
        -> Producer a' m a
        -> Constant
             (Proxy X () () a' m (Producer a' m a)) (Producer a' m a))
    -> Proxy X () () a' m (Producer a' m a)
    forall a b. a -> ((b -> Constant b b) -> a -> Constant b a) -> b
    ^. (a' -> Bool)
    -> Lens' (Producer a' m a) (Proxy X () () a' m (Producer a' m a))
    forall (m :: * -> *) a x.
    Monad m =>
    (a -> Bool)
    -> Lens' (Producer a m x) (Producer a m (Producer a m x))
    span (a' -> a' -> Bool
    equals a'
    a)))
    {-# INLINABLE groupsBy #-}

    {-| `groupsBy'` splits a 'Producer' into a 'FreeT' of 'Producer's grouped using
        the given equality predicate

        This differs from `groupsBy` by comparing successive elements for equality
        instead of comparing each element to the first member of the group

    >>> import Lens.Family (view)
    >>> import Pipes (yield, each)
    >>> import Pipes.Prelude (toList)
    >>> let cmp c1 c2 = succ c1 == c2
    >>> (toList . intercalates (yield '|') . view (groupsBy' cmp)) (each "12233345")
    "12|23|3|345"
    >>> (toList . intercalates (yield '|') . view (groupsBy  cmp)) (each "12233345")
    "122|3|3|34|5"

    @
          groupsBy' p  :: Monad m => Lens' ('Producer' a m x) (Groups a m x)
    view (groupsBy' p) :: Monad m => Splitter a m x
    set  (groupsBy' p) :: Monad m => Groups a m x -> 'Producer' a m x -> 'Producer' a m x
    over (groupsBy' p) :: Monad m => Transformation a m x -> 'Producer' a m x -> 'Producer' a m x
    @
    -}
    groupsBy'
        :: Monad m
        => (a' -> a' -> Bool) -> Lens (Producer a' m x) (Producer a m x) (FreeT (Producer a' m) m x) (FreeT (Producer a m) m x)
    groupsBy' :: forall (m :: * -> *) a' x a.
    Monad m =>
    (a' -> a' -> Bool)
    -> Lens
         (Producer a' m x)
         (Producer a m x)
         (FreeT (Producer a' m) m x)
         (FreeT (Producer a m) m x)
    groupsBy' a' -> a' -> Bool
    equals FreeT (Producer a' m) m x -> f (FreeT (Producer a m) m x)
    k Producer a' m x
    p0 = (FreeT (Producer a m) m x -> Producer a m x)
    -> f (FreeT (Producer a m) m x) -> f (Producer a m x)
    forall a b. (a -> b) -> f a -> f b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap FreeT (Producer a m) m x -> Producer a m x
    forall (m :: * -> *) a x.
    Monad m =>
    FreeT (Producer a m) m x -> Producer a m x
    concats (FreeT (Producer a' m) m x -> f (FreeT (Producer a m) m x)
    k (Producer a' m x -> FreeT (Producer a' m) m x
    forall {m :: * -> *} {a} {x'} {x}.
    Monad m =>
    Proxy X () () a' m a -> FreeT (Proxy x' x () a' m) m a
    _groupsBy Producer a' m x
    p0))
      where
    --  _groupsBy :: Monad m => Producer a m r -> FreeT (Producer a m) m r
        _groupsBy :: Proxy X () () a' m a -> FreeT (Proxy x' x () a' m) m a
    _groupsBy Proxy X () () a' m a
    p = m (FreeF (Proxy x' x () a' m) a (FreeT (Proxy x' x () a' m) m a))
    -> FreeT (Proxy x' x () a' m) m a
    forall (f :: * -> *) (m :: * -> *) a.
    m (FreeF f a (FreeT f m a)) -> FreeT f m a
    FreeT (m (FreeF (Proxy x' x () a' m) a (FreeT (Proxy x' x () a' m) m a))
     -> FreeT (Proxy x' x () a' m) m a)
    -> m (FreeF
            (Proxy x' x () a' m) a (FreeT (Proxy x' x () a' m) m a))
    -> FreeT (Proxy x' x () a' m) m a
    forall a b. (a -> b) -> a -> b
    $ do
            Either a (a', Proxy X () () a' m a)
    x <- Proxy X () () a' m a -> m (Either a (a', Proxy X () () a' m a))
    forall (m :: * -> *) a r.
    Monad m =>
    Producer a m r -> m (Either r (a, Producer a m r))
    next Proxy X () () a' m a
    p
            FreeF (Proxy x' x () a' m) a (FreeT (Proxy x' x () a' m) m a)
    -> m (FreeF
            (Proxy x' x () a' m) a (FreeT (Proxy x' x () a' m) m a))
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (FreeF (Proxy x' x () a' m) a (FreeT (Proxy x' x () a' m) m a)
     -> m (FreeF
             (Proxy x' x () a' m) a (FreeT (Proxy x' x () a' m) m a)))
    -> FreeF (Proxy x' x () a' m) a (FreeT (Proxy x' x () a' m) m a)
    -> m (FreeF
            (Proxy x' x () a' m) a (FreeT (Proxy x' x () a' m) m a))
    forall a b. (a -> b) -> a -> b
    $ case Either a (a', Proxy X () () a' m a)
    x of
                Left   a
    r      -> a -> FreeF (Proxy x' x () a' m) a (FreeT (Proxy x' x () a' m) m a)
    forall (f :: * -> *) a b. a -> FreeF f a b
    Pure a
    r
                Right (a'
    a, Proxy X () () a' m a
    p') -> Proxy x' x () a' m (FreeT (Proxy x' x () a' m) m a)
    -> FreeF (Proxy x' x () a' m) a (FreeT (Proxy x' x () a' m) m a)
    forall (f :: * -> *) a b. f b -> FreeF f a b
    Free ((Proxy X () () a' m a -> FreeT (Proxy x' x () a' m) m a)
    -> Proxy x' x () a' m (Proxy X () () a' m a)
    -> Proxy x' x () a' m (FreeT (Proxy x' x () a' m) m a)
    forall a b.
    (a -> b) -> Proxy x' x () a' m a -> Proxy x' x () a' m b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap Proxy X () () a' m a -> FreeT (Proxy x' x () a' m) m a
    _groupsBy (Proxy X () () a' m a -> Proxy x' x () a' m (Proxy X () () a' m a)
    forall {m :: * -> *} {a} {x'} {x}.
    Monad m =>
    Producer a' m a -> Proxy x' x () a' m (Producer a' m a)
    loop0 (a' -> Proxy X () () a' m ()
    forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
    yield a'
    a Proxy X () () a' m ()
    -> Proxy X () () a' m a -> Proxy X () () a' m a
    forall a b.
    Proxy X () () a' m a
    -> Proxy X () () a' m b -> Proxy X () () a' m b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> Proxy X () () a' m a
    p')))

    --  loop0
    --      :: Monad m
    --      => Producer a m r
    --      -> Producer a m (Producer a m r)
        loop0 :: Producer a' m a -> Proxy x' x () a' m (Producer a' m a)
    loop0 Producer a' m a
    p1 = do
            Either a (a', Producer a' m a)
    x <- m (Either a (a', Producer a' m a))
    -> Proxy x' x () a' m (Either a (a', Producer a' m a))
    forall (m :: * -> *) a. Monad m => m a -> Proxy x' x () a' m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (Producer a' m a -> m (Either a (a', Producer a' m a))
    forall (m :: * -> *) a r.
    Monad m =>
    Producer a m r -> m (Either r (a, Producer a m r))
    next Producer a' m a
    p1)
            case Either a (a', Producer a' m a)
    x of
                Left   a
    r      -> Producer a' m a -> Proxy x' x () a' m (Producer a' m a)
    forall a. a -> Proxy x' x () a' m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (a -> Producer a' m a
    forall a. a -> Proxy X () () a' m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return a
    r)
                Right (a'
    a2, Producer a' m a
    p2) -> do
                    a' -> Proxy x' x () a' m ()
    forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
    yield a'
    a2
                    let loop1 :: a' -> Producer a' m a -> Proxy x' x () a' m (Producer a' m a)
    loop1 a'
    a Producer a' m a
    p = do
                            Either a (a', Producer a' m a)
    y <- m (Either a (a', Producer a' m a))
    -> Proxy x' x () a' m (Either a (a', Producer a' m a))
    forall (m :: * -> *) a. Monad m => m a -> Proxy x' x () a' m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (Producer a' m a -> m (Either a (a', Producer a' m a))
    forall (m :: * -> *) a r.
    Monad m =>
    Producer a m r -> m (Either r (a, Producer a m r))
    next Producer a' m a
    p)
                            case Either a (a', Producer a' m a)
    y of
                                Left   a
    r      -> Producer a' m a -> Proxy x' x () a' m (Producer a' m a)
    forall a. a -> Proxy x' x () a' m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (a -> Producer a' m a
    forall a. a -> Proxy X () () a' m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return a
    r)
                                Right (a'
    a', Producer a' m a
    p') ->
                                    if a' -> a' -> Bool
    equals a'
    a a'
    a'
                                    then do
                                        a' -> Proxy x' x () a' m ()
    forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
    yield a'
    a'
                                        a' -> Producer a' m a -> Proxy x' x () a' m (Producer a' m a)
    loop1 a'
    a' Producer a' m a
    p'
                                    else Producer a' m a -> Proxy x' x () a' m (Producer a' m a)
    forall a. a -> Proxy x' x () a' m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (a' -> Proxy X () () a' m ()
    forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
    yield a'
    a' Proxy X () () a' m () -> Producer a' m a -> Producer a' m a
    forall a b.
    Proxy X () () a' m a
    -> Proxy X () () a' m b -> Proxy X () () a' m b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> Producer a' m a
    p')
                    a' -> Producer a' m a -> Proxy x' x () a' m (Producer a' m a)
    forall {m :: * -> *} {a} {x'} {x}.
    Monad m =>
    a' -> Producer a' m a -> Proxy x' x () a' m (Producer a' m a)
    loop1 a'
    a2 Producer a' m a
    p2
    {-# INLINABLE groupsBy' #-}

    {-| Like 'groupsBy', where the equality predicate is ('==')

    @
         groups :: Monad m => Lens' ('Producer' a m x) (Groups a m x)
    view groups :: Monad m => Splitter a m x
    set  groups :: Monad m => Groups a m x -> 'Producer' a m x -> 'Producer' a m x
    over groups :: Monad m => Transformation a m x -> 'Producer' a m x -> 'Producer' a m x
    @

    >>> import Lens.Family (view)
    >>> import Pipes (yield, each)
    >>> import Pipes.Prelude (toList)
    >>> (toList . intercalates (yield '|') . view groups) (each "12233345")
    "1|22|333|4|5"
    -}
    groups :: (Monad m, Eq a') => Lens (Producer a' m x) (Producer a m x) (FreeT (Producer a' m) m x) (FreeT (Producer a m) m x)
    groups :: forall (m :: * -> *) a' x a.
    (Monad m, Eq a') =>
    Lens
      (Producer a' m x)
      (Producer a m x)
      (FreeT (Producer a' m) m x)
      (FreeT (Producer a m) m x)
    groups = (a' -> a' -> Bool)
    -> Lens
         (Producer a' m x)
         (Producer a m x)
         (FreeT (Producer a' m) m x)
         (FreeT (Producer a m) m x)
    forall (m :: * -> *) a' x a.
    Monad m =>
    (a' -> a' -> Bool)
    -> Lens
         (Producer a' m x)
         (Producer a m x)
         (FreeT (Producer a' m) m x)
         (FreeT (Producer a m) m x)
    groupsBy a' -> a' -> Bool
    forall a. Eq a => a -> a -> Bool
    (==)
    {-# INLINABLE groups #-}

    {-| 'chunksOf' is an splits a 'Producer' into a 'FreeT' of 'Producer's of fixed
        length

    @
          chunksOf n  :: Monad m => Lens' ('Producer' a m x) (Groups a m x)
    view (chunksOf n) :: Monad m => Splitter a m x
    set  (chunksOf n) :: Monad m => Groups a m x -> 'Producer' a m x -> 'Producer' a m x
    over (chunksOf n) :: Monad m => Transformation a m x -> 'Producer' a m x -> 'Producer' a m x
    @

    >>> import Lens.Family (view)
    >>> import Pipes (yield, each)
    >>> import Pipes.Prelude (toList)
    >>> (toList . intercalates (yield '|') . view (chunksOf 3)) (each "12233345")
    "122|333|45"
    -}
    chunksOf
        :: Monad m => Int -> Lens (Producer a' m x) (Producer a m x) (FreeT (Producer a' m) m x) (FreeT (Producer a m) m x)
    chunksOf :: forall (m :: * -> *) a' x a.
    Monad m =>
    Int
    -> Lens
         (Producer a' m x)
         (Producer a m x)
         (FreeT (Producer a' m) m x)
         (FreeT (Producer a m) m x)
    chunksOf Int
    n0 FreeT (Producer a' m) m x -> f (FreeT (Producer a m) m x)
    k Producer a' m x
    p0 = (FreeT (Producer a m) m x -> Producer a m x)
    -> f (FreeT (Producer a m) m x) -> f (Producer a m x)
    forall a b. (a -> b) -> f a -> f b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap FreeT (Producer a m) m x -> Producer a m x
    forall (m :: * -> *) a x.
    Monad m =>
    FreeT (Producer a m) m x -> Producer a m x
    concats (FreeT (Producer a' m) m x -> f (FreeT (Producer a m) m x)
    k (Producer a' m x -> FreeT (Producer a' m) m x
    forall {m :: * -> *} {a} {b}.
    Monad m =>
    Producer a m b -> FreeT (Proxy X () () a m) m b
    _chunksOf Producer a' m x
    p0))
      where
    --  _chunksOf :: Monad m => Producer a m x -> FreeT (Producer a m) m x
        _chunksOf :: Producer a m b -> FreeT (Proxy X () () a m) m b
    _chunksOf Producer a m b
    p = m (FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b))
    -> FreeT (Proxy X () () a m) m b
    forall (f :: * -> *) (m :: * -> *) a.
    m (FreeF f a (FreeT f m a)) -> FreeT f m a
    FreeT (m (FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b))
     -> FreeT (Proxy X () () a m) m b)
    -> m (FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b))
    -> FreeT (Proxy X () () a m) m b
    forall a b. (a -> b) -> a -> b
    $ do
            Either b (a, Producer a m b)
    x <- Producer a m b -> m (Either b (a, Producer a m b))
    forall (m :: * -> *) a r.
    Monad m =>
    Producer a m r -> m (Either r (a, Producer a m r))
    next Producer a m b
    p
            FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b)
    -> m (FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b))
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b)
     -> m (FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b)))
    -> FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b)
    -> m (FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b))
    forall a b. (a -> b) -> a -> b
    $ case Either b (a, Producer a m b)
    x of
                Left   b
    r      -> b -> FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b)
    forall (f :: * -> *) a b. a -> FreeF f a b
    Pure b
    r
                Right (a
    a, Producer a m b
    p') -> Proxy X () () a m (FreeT (Proxy X () () a m) m b)
    -> FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b)
    forall (f :: * -> *) a b. f b -> FreeF f a b
    Free (Proxy X () () a m (FreeT (Proxy X () () a m) m b)
     -> FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b))
    -> Proxy X () () a m (FreeT (Proxy X () () a m) m b)
    -> FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b)
    forall a b. (a -> b) -> a -> b
    $ (Producer a m b -> FreeT (Proxy X () () a m) m b)
    -> Proxy X () () a m (Producer a m b)
    -> Proxy X () () a m (FreeT (Proxy X () () a m) m b)
    forall a b. (a -> b) -> Proxy X () () a m a -> Proxy X () () a m b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap Producer a m b -> FreeT (Proxy X () () a m) m b
    _chunksOf ((a -> Proxy X () () a m ()
    forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
    yield a
    a Proxy X () () a m () -> Producer a m b -> Producer a m b
    forall a b.
    Proxy X () () a m a -> Proxy X () () a m b -> Proxy X () () a m b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> Producer a m b
    p')Producer a m b
    -> ((Proxy X () () a m (Producer a m b)
         -> Constant
              (Proxy X () () a m (Producer a m b))
              (Proxy X () () a m (Producer a m b)))
        -> Producer a m b
        -> Constant (Proxy X () () a m (Producer a m b)) (Producer a m b))
    -> Proxy X () () a m (Producer a m b)
    forall a b. a -> ((b -> Constant b b) -> a -> Constant b a) -> b
    ^.Int -> Lens' (Producer a m b) (Proxy X () () a m (Producer a m b))
    forall (m :: * -> *) a x.
    Monad m =>
    Int -> Lens' (Producer a m x) (Producer a m (Producer a m x))
    splitAt Int
    n0)
    {-# INLINABLE chunksOf #-}

    -- | Join a 'FreeT'-delimited stream of 'Producer's into a single 'Producer'
    --
    -- @
    -- concats :: Monad m => Joiner a m x
    -- @
    concats :: Monad m => FreeT (Producer a m) m x -> Producer a m x
    concats :: forall (m :: * -> *) a x.
    Monad m =>
    FreeT (Producer a m) m x -> Producer a m x
    concats = FreeT (Proxy X () () a m) m x -> Proxy X () () a m x
    forall {t :: (* -> *) -> * -> *} {m :: * -> *} {b}.
    (MonadTrans t, Monad m, Monad (t m)) =>
    FreeT (t m) m b -> t m b
    go
      where
        go :: FreeT (t m) m b -> t m b
    go FreeT (t m) m b
    f = do
            FreeF (t m) b (FreeT (t m) m b)
    x <- m (FreeF (t m) b (FreeT (t m) m b))
    -> t m (FreeF (t m) b (FreeT (t m) m b))
    forall (m :: * -> *) a. Monad m => m a -> t m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (FreeT (t m) m b -> m (FreeF (t m) b (FreeT (t m) m b))
    forall (f :: * -> *) (m :: * -> *) a.
    FreeT f m a -> m (FreeF f a (FreeT f m a))
    runFreeT FreeT (t m) m b
    f)
            case FreeF (t m) b (FreeT (t m) m b)
    x of
                Pure b
    r -> b -> t m b
    forall a. a -> t m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return b
    r
                Free t m (FreeT (t m) m b)
    p -> do
                    FreeT (t m) m b
    f' <- t m (FreeT (t m) m b)
    p
                    FreeT (t m) m b -> t m b
    go FreeT (t m) m b
    f'
    {-# INLINABLE concats #-}

    {-| Join a 'FreeT'-delimited stream of 'Producer's into a single 'Producer' by
        intercalating a 'Producer' in between them

    @
    intercalates :: Monad m => 'Producer' a m () -> Joiner a m x
    @
    -}
    intercalates
        :: Monad m => Producer a m () -> FreeT (Producer a m) m x -> Producer a m x
    intercalates :: forall (m :: * -> *) a x.
    Monad m =>
    Producer a m () -> FreeT (Producer a m) m x -> Producer a m x
    intercalates Producer a m ()
    sep = FreeT (Proxy X () () a m) m x -> Proxy X () () a m x
    forall {b}. FreeT (Proxy X () () a m) m b -> Proxy X () () a m b
    go0
      where
        go0 :: FreeT (Proxy X () () a m) m b -> Proxy X () () a m b
    go0 FreeT (Proxy X () () a m) m b
    f = do
            FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b)
    x <- m (FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b))
    -> Proxy
         X
         ()
         ()
         a
         m
         (FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b))
    forall (m :: * -> *) a. Monad m => m a -> Proxy X () () a m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (FreeT (Proxy X () () a m) m b
    -> m (FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b))
    forall (f :: * -> *) (m :: * -> *) a.
    FreeT f m a -> m (FreeF f a (FreeT f m a))
    runFreeT FreeT (Proxy X () () a m) m b
    f)
            case FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b)
    x of
                Pure b
    r -> b -> Proxy X () () a m b
    forall a. a -> Proxy X () () a m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return b
    r
                Free Proxy X () () a m (FreeT (Proxy X () () a m) m b)
    p -> do
                    FreeT (Proxy X () () a m) m b
    f' <- Proxy X () () a m (FreeT (Proxy X () () a m) m b)
    p
                    FreeT (Proxy X () () a m) m b -> Proxy X () () a m b
    forall {b}. FreeT (Proxy X () () a m) m b -> Proxy X () () a m b
    go1 FreeT (Proxy X () () a m) m b
    f'
        go1 :: FreeT (Proxy X () () a m) m b -> Proxy X () () a m b
    go1 FreeT (Proxy X () () a m) m b
    f = do
            FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b)
    x <- m (FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b))
    -> Proxy
         X
         ()
         ()
         a
         m
         (FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b))
    forall (m :: * -> *) a. Monad m => m a -> Proxy X () () a m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (FreeT (Proxy X () () a m) m b
    -> m (FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b))
    forall (f :: * -> *) (m :: * -> *) a.
    FreeT f m a -> m (FreeF f a (FreeT f m a))
    runFreeT FreeT (Proxy X () () a m) m b
    f)
            case FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b)
    x of
                Pure b
    r -> b -> Proxy X () () a m b
    forall a. a -> Proxy X () () a m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return b
    r
                Free Proxy X () () a m (FreeT (Proxy X () () a m) m b)
    p -> do
                    Producer a m ()
    sep
                    FreeT (Proxy X () () a m) m b
    f' <- Proxy X () () a m (FreeT (Proxy X () () a m) m b)
    p
                    FreeT (Proxy X () () a m) m b -> Proxy X () () a m b
    go1 FreeT (Proxy X () () a m) m b
    f'
    {-# INLINABLE intercalates #-}

    {-| @(takes n)@ only keeps the first @n@ functor layers of a 'FreeT'

    @
    takes :: Monad m => Int -> Groups a m () -> Groups a m ()
    @

    >>> import Lens.Family (view)
    >>> import Pipes (yield, each)
    >>> import Pipes.Prelude (toList)
    >>> (toList . intercalates (yield '|') . takes 3 . view groups) (each "12233345")
    "1|22|333"
    -}
    takes :: (Functor f, Monad m) => Int -> FreeT f m () -> FreeT f m ()
    takes :: forall (f :: * -> *) (m :: * -> *).
    (Functor f, Monad m) =>
    Int -> FreeT f m () -> FreeT f m ()
    takes = Int -> FreeT f m () -> FreeT f m ()
    forall {a} {m :: * -> *} {f :: * -> *}.
    (Ord a, Num a, Monad m, Functor f) =>
    a -> FreeT f m () -> FreeT f m ()
    go
      where
        go :: a -> FreeT f m () -> FreeT f m ()
    go a
    n FreeT f m ()
    f =
            if (a
    n a -> a -> Bool
    forall a. Ord a => a -> a -> Bool
    > a
    0)
            then m (FreeF f () (FreeT f m ())) -> FreeT f m ()
    forall (f :: * -> *) (m :: * -> *) a.
    m (FreeF f a (FreeT f m a)) -> FreeT f m a
    FreeT (m (FreeF f () (FreeT f m ())) -> FreeT f m ())
    -> m (FreeF f () (FreeT f m ())) -> FreeT f m ()
    forall a b. (a -> b) -> a -> b
    $ do
                FreeF f () (FreeT f m ())
    x <- FreeT f m () -> m (FreeF f () (FreeT f m ()))
    forall (f :: * -> *) (m :: * -> *) a.
    FreeT f m a -> m (FreeF f a (FreeT f m a))
    runFreeT FreeT f m ()
    f
                case FreeF f () (FreeT f m ())
    x of
                    Pure () -> FreeF f () (FreeT f m ()) -> m (FreeF f () (FreeT f m ()))
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (() -> FreeF f () (FreeT f m ())
    forall (f :: * -> *) a b. a -> FreeF f a b
    Pure ())
                    Free f (FreeT f m ())
    w  -> FreeF f () (FreeT f m ()) -> m (FreeF f () (FreeT f m ()))
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (f (FreeT f m ()) -> FreeF f () (FreeT f m ())
    forall (f :: * -> *) a b. f b -> FreeF f a b
    Free ((FreeT f m () -> FreeT f m ())
    -> f (FreeT f m ()) -> f (FreeT f m ())
    forall a b. (a -> b) -> f a -> f b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap (a -> FreeT f m () -> FreeT f m ()
    go (a -> FreeT f m () -> FreeT f m ())
    -> a -> FreeT f m () -> FreeT f m ()
    forall a b. (a -> b) -> a -> b
    $! a
    n a -> a -> a
    forall a. Num a => a -> a -> a
    - a
    1) f (FreeT f m ())
    w))
            else () -> FreeT f m ()
    forall a. a -> FreeT f m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ()
    {-# INLINABLE takes #-}

    {-| @(takes' n)@ only keeps the first @n@ 'Producer's of a 'FreeT'

        'takes'' differs from 'takes' by draining unused 'Producer's in order
        to preserve the return value.  This makes it a suitable argument for 'maps'.

    @
    takes' :: Monad m => Int -> Transformation a m x
    @
    -}
    takes' :: Monad m => Int -> FreeT (Producer a m) m x -> FreeT (Producer a m) m x
    takes' :: forall (m :: * -> *) a x.
    Monad m =>
    Int -> FreeT (Producer a m) m x -> FreeT (Producer a m) m x
    takes' = Int
    -> FreeT (Proxy X () () a m) m x -> FreeT (Proxy X () () a m) m x
    forall {a} {m :: * -> *} {b} {a}.
    (Ord a, Num a, Monad m) =>
    a -> FreeT (Proxy X () () b m) m a -> FreeT (Proxy X () () b m) m a
    go0
      where
        go0 :: a -> FreeT (Proxy X () () b m) m a -> FreeT (Proxy X () () b m) m a
    go0 a
    n FreeT (Proxy X () () b m) m a
    f = m (FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a))
    -> FreeT (Proxy X () () b m) m a
    forall (f :: * -> *) (m :: * -> *) a.
    m (FreeF f a (FreeT f m a)) -> FreeT f m a
    FreeT (m (FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a))
     -> FreeT (Proxy X () () b m) m a)
    -> m (FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a))
    -> FreeT (Proxy X () () b m) m a
    forall a b. (a -> b) -> a -> b
    $
            if (a
    n a -> a -> Bool
    forall a. Ord a => a -> a -> Bool
    > a
    0)
            then do
                FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a)
    x <- FreeT (Proxy X () () b m) m a
    -> m (FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a))
    forall (f :: * -> *) (m :: * -> *) a.
    FreeT f m a -> m (FreeF f a (FreeT f m a))
    runFreeT FreeT (Proxy X () () b m) m a
    f
                FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a)
    -> m (FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a))
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a)
     -> m (FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a)))
    -> FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a)
    -> m (FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a))
    forall a b. (a -> b) -> a -> b
    $ case FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a)
    x of
                    Pure a
    r -> a -> FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a)
    forall (f :: * -> *) a b. a -> FreeF f a b
    Pure a
    r
                    Free Proxy X () () b m (FreeT (Proxy X () () b m) m a)
    p -> Proxy X () () b m (FreeT (Proxy X () () b m) m a)
    -> FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a)
    forall (f :: * -> *) a b. f b -> FreeF f a b
    Free (Proxy X () () b m (FreeT (Proxy X () () b m) m a)
     -> FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a))
    -> Proxy X () () b m (FreeT (Proxy X () () b m) m a)
    -> FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a)
    forall a b. (a -> b) -> a -> b
    $ (FreeT (Proxy X () () b m) m a -> FreeT (Proxy X () () b m) m a)
    -> Proxy X () () b m (FreeT (Proxy X () () b m) m a)
    -> Proxy X () () b m (FreeT (Proxy X () () b m) m a)
    forall a b. (a -> b) -> Proxy X () () b m a -> Proxy X () () b m b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap (a -> FreeT (Proxy X () () b m) m a -> FreeT (Proxy X () () b m) m a
    go0 (a
     -> FreeT (Proxy X () () b m) m a -> FreeT (Proxy X () () b m) m a)
    -> a
    -> FreeT (Proxy X () () b m) m a
    -> FreeT (Proxy X () () b m) m a
    forall a b. (a -> b) -> a -> b
    $! a
    n a -> a -> a
    forall a. Num a => a -> a -> a
    - a
    1) Proxy X () () b m (FreeT (Proxy X () () b m) m a)
    p
            else FreeT (Proxy X () () b m) m a
    -> m (FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a))
    forall {m :: * -> *} {b} {a} {f :: * -> *} {b}.
    Monad m =>
    FreeT (Proxy X () () b m) m a -> m (FreeF f a b)
    go1 FreeT (Proxy X () () b m) m a
    f
        go1 :: FreeT (Proxy X () () b m) m a -> m (FreeF f a b)
    go1 FreeT (Proxy X () () b m) m a
    f = do
            FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a)
    x <- FreeT (Proxy X () () b m) m a
    -> m (FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a))
    forall (f :: * -> *) (m :: * -> *) a.
    FreeT f m a -> m (FreeF f a (FreeT f m a))
    runFreeT FreeT (Proxy X () () b m) m a
    f
            case FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a)
    x of
                Pure a
    r -> FreeF f a b -> m (FreeF f a b)
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (a -> FreeF f a b
    forall (f :: * -> *) a b. a -> FreeF f a b
    Pure a
    r)
                Free Proxy X () () b m (FreeT (Proxy X () () b m) m a)
    p -> do
                    FreeT (Proxy X () () b m) m a
    f' <- Effect m (FreeT (Proxy X () () b m) m a)
    -> m (FreeT (Proxy X () () b m) m a)
    forall (m :: * -> *) r. Monad m => Effect m r -> m r
    P.runEffect (Proxy X () () b m (FreeT (Proxy X () () b m) m a)
    -> (b -> Proxy X () () X m ())
    -> Effect m (FreeT (Proxy X () () b m) m a)
    forall (m :: * -> *) x' x b' b a' c' c.
    Functor m =>
    Proxy x' x b' b m a'
    -> (b -> Proxy x' x c' c m b') -> Proxy x' x c' c m a'
    P.for Proxy X () () b m (FreeT (Proxy X () () b m) m a)
    p b -> Proxy X () () X m ()
    forall (m :: * -> *) a. Monad m => a -> m ()
    P.discard)
                    FreeT (Proxy X () () b m) m a -> m (FreeF f a b)
    go1 FreeT (Proxy X () () b m) m a
    f'
    {-# INLINABLE takes' #-}

    {-| @(drops n)@ peels off the first @n@ 'Producer' layers of a 'FreeT'

    @
    drops :: Monad m => Int -> Transformation a m x
    @

    >>> import Lens.Family (view)
    >>> import Pipes (yield, each)
    >>> import Pipes.Prelude (toList)
    >>> (toList . intercalates (yield '|') . drops 3 . view groups) (each "12233345")
    "4|5"

        __Use carefully__: the peeling off is not free.   This runs the first @n@
        layers, just discarding everything they produce.
    -}
    drops :: Monad m => Int -> FreeT (Producer a m) m x -> FreeT (Producer a m) m x
    drops :: forall (m :: * -> *) a x.
    Monad m =>
    Int -> FreeT (Producer a m) m x -> FreeT (Producer a m) m x
    drops = Int
    -> FreeT (Proxy X () () a m) m x -> FreeT (Proxy X () () a m) m x
    forall {a} {m :: * -> *} {b} {a}.
    (Ord a, Num a, Monad m) =>
    a -> FreeT (Proxy X () () b m) m a -> FreeT (Proxy X () () b m) m a
    go
      where
        go :: t -> FreeT (Proxy X () () b m) m a -> FreeT (Proxy X () () b m) m a
    go t
    n FreeT (Proxy X () () b m) m a
    ft
            | t
    n t -> t -> Bool
    forall a. Ord a => a -> a -> Bool
    <= t
    0 = FreeT (Proxy X () () b m) m a
    ft
            | Bool
    otherwise = m (FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a))
    -> FreeT (Proxy X () () b m) m a
    forall (f :: * -> *) (m :: * -> *) a.
    m (FreeF f a (FreeT f m a)) -> FreeT f m a
    FreeT (m (FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a))
     -> FreeT (Proxy X () () b m) m a)
    -> m (FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a))
    -> FreeT (Proxy X () () b m) m a
    forall a b. (a -> b) -> a -> b
    $ do
                FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a)
    ff <- FreeT (Proxy X () () b m) m a
    -> m (FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a))
    forall (f :: * -> *) (m :: * -> *) a.
    FreeT f m a -> m (FreeF f a (FreeT f m a))
    runFreeT FreeT (Proxy X () () b m) m a
    ft
                case FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a)
    ff of
                    Pure a
    _ -> FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a)
    -> m (FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a))
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a)
    ff
                    Free Proxy X () () b m (FreeT (Proxy X () () b m) m a)
    f -> do
                        FreeT (Proxy X () () b m) m a
    ft' <- Effect m (FreeT (Proxy X () () b m) m a)
    -> m (FreeT (Proxy X () () b m) m a)
    forall (m :: * -> *) r. Monad m => Effect m r -> m r
    P.runEffect (Effect m (FreeT (Proxy X () () b m) m a)
     -> m (FreeT (Proxy X () () b m) m a))
    -> Effect m (FreeT (Proxy X () () b m) m a)
    -> m (FreeT (Proxy X () () b m) m a)
    forall a b. (a -> b) -> a -> b
    $ Proxy X () () b m (FreeT (Proxy X () () b m) m a)
    -> (b -> Proxy X () () X m ())
    -> Effect m (FreeT (Proxy X () () b m) m a)
    forall (m :: * -> *) x' x b' b a' c' c.
    Functor m =>
    Proxy x' x b' b m a'
    -> (b -> Proxy x' x c' c m b') -> Proxy x' x c' c m a'
    P.for Proxy X () () b m (FreeT (Proxy X () () b m) m a)
    f b -> Proxy X () () X m ()
    forall (m :: * -> *) a. Monad m => a -> m ()
    P.discard
                        FreeT (Proxy X () () b m) m a
    -> m (FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a))
    forall (f :: * -> *) (m :: * -> *) a.
    FreeT f m a -> m (FreeF f a (FreeT f m a))
    runFreeT (FreeT (Proxy X () () b m) m a
     -> m (FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a)))
    -> FreeT (Proxy X () () b m) m a
    -> m (FreeF (Proxy X () () b m) a (FreeT (Proxy X () () b m) m a))
    forall a b. (a -> b) -> a -> b
    $ t -> FreeT (Proxy X () () b m) m a -> FreeT (Proxy X () () b m) m a
    go (t
    nt -> t -> t
    forall a. Num a => a -> a -> a
    -t
    1) FreeT (Proxy X () () b m) m a
    ft'
    {-# INLINABLE drops #-}

    {-| Transform each individual functor layer of a 'FreeT'

        You can think of this as:

    > maps
    >     :: (forall r . Producer a m r -> Producer b m r)
    >     -> FreeT (Producer a m) m x -> FreeT (Producer b m) m x

        This is just a synonym for 'F.transFreeT'
    -}
    maps
        :: (Monad m, Functor g)
        => (forall r . f r -> g r) -> FreeT f m x -> FreeT g m x
    maps :: forall (m :: * -> *) (g :: * -> *) (f :: * -> *) x.
    (Monad m, Functor g) =>
    (forall r. f r -> g r) -> FreeT f m x -> FreeT g m x
    maps = (forall a. f a -> g a) -> FreeT f m x -> FreeT g m x
    forall (m :: * -> *) (g :: * -> *) (f :: * -> *) x.
    (Monad m, Functor g) =>
    (forall r. f r -> g r) -> FreeT f m x -> FreeT g m x
    F.transFreeT
    {-# INLINABLE maps #-}

    {-| Lens to transform each individual functor layer of a 'FreeT'. (@over
        'individually'@) is equivalent to 'maps', but with a less general type.

    @
    type Group a m x = 'Producer' a m (Groups a m x)

    set  individually :: Monad m => Group a m x -> Transformation a m x
    over individually :: Monad m => (Group a m x -> Group a m x) -> Transformation a m x
    @
    -}
    individually
        :: (Monad m, Functor g)
        => Setter (FreeT f m x) (FreeT g m x) (f (FreeT f m x)) (g (FreeT f m x))
    individually :: forall (m :: * -> *) (g :: * -> *) (f :: * -> *) x.
    (Monad m, Functor g) =>
    Setter
      (FreeT f m x) (FreeT g m x) (f (FreeT f m x)) (g (FreeT f m x))
    individually f (FreeT f m x) -> Identity (g (FreeT f m x))
    nat FreeT f m x
    f0 = FreeT g m x -> Identity (FreeT g m x)
    forall a. a -> Identity a
    Identity (FreeT f m x -> FreeT g m x
    go FreeT f m x
    f0)
      where
        nat' :: f (FreeT f m x) -> g (FreeT f m x)
    nat' = Identity (g (FreeT f m x)) -> g (FreeT f m x)
    forall a. Identity a -> a
    runIdentity (Identity (g (FreeT f m x)) -> g (FreeT f m x))
    -> (f (FreeT f m x) -> Identity (g (FreeT f m x)))
    -> f (FreeT f m x)
    -> g (FreeT f m x)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . f (FreeT f m x) -> Identity (g (FreeT f m x))
    nat
        go :: FreeT f m x -> FreeT g m x
    go FreeT f m x
    f = m (FreeF g x (FreeT g m x)) -> FreeT g m x
    forall (f :: * -> *) (m :: * -> *) a.
    m (FreeF f a (FreeT f m a)) -> FreeT f m a
    FreeT (m (FreeF g x (FreeT g m x)) -> FreeT g m x)
    -> m (FreeF g x (FreeT g m x)) -> FreeT g m x
    forall a b. (a -> b) -> a -> b
    $ do
            FreeF f x (FreeT f m x)
    x <- FreeT f m x -> m (FreeF f x (FreeT f m x))
    forall (f :: * -> *) (m :: * -> *) a.
    FreeT f m a -> m (FreeF f a (FreeT f m a))
    runFreeT FreeT f m x
    f
            FreeF g x (FreeT g m x) -> m (FreeF g x (FreeT g m x))
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (FreeF g x (FreeT g m x) -> m (FreeF g x (FreeT g m x)))
    -> FreeF g x (FreeT g m x) -> m (FreeF g x (FreeT g m x))
    forall a b. (a -> b) -> a -> b
    $ case FreeF f x (FreeT f m x)
    x of
                Pure x
    r -> x -> FreeF g x (FreeT g m x)
    forall (f :: * -> *) a b. a -> FreeF f a b
    Pure x
    r
                Free f (FreeT f m x)
    w -> g (FreeT g m x) -> FreeF g x (FreeT g m x)
    forall (f :: * -> *) a b. f b -> FreeF f a b
    Free ((FreeT f m x -> FreeT g m x) -> g (FreeT f m x) -> g (FreeT g m x)
    forall a b. (a -> b) -> g a -> g b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap FreeT f m x -> FreeT g m x
    go (f (FreeT f m x) -> g (FreeT f m x)
    nat' f (FreeT f m x)
    w))
    {-# INLINABLE individually #-}

    {- $folds
        These folds are designed to be compatible with the @foldl@ library.  See
        the 'Control.Foldl.purely' and 'Control.Foldl.impurely' functions from that
        library for more details.

        For example, to count the number of 'Producer' layers in a 'FreeT', you can
        write:

    > import Control.Applicative (pure)
    > import qualified Control.Foldl as L
    > import Pipes.Group
    > import qualified Pipes.Prelude as P
    >
    > count :: Monad m => FreeT (Producer a m) m () -> m Int
    > count = P.sum . L.purely folds (pure 1)
    -}
    {-| Fold each 'Producer' of a 'FreeT'

    @
    'Control.Foldl.purely' folds :: Monad m => 'Control.Foldl.Fold' a b -> Groups a m r -> 'Producer' b m r
    @
    -}
    folds
        :: Monad m
        => (x -> a -> x)
        -- ^ Step function
        -> x
        -- ^ Initial accumulator
        -> (x -> b)
        -- ^ Extraction function
        -> FreeT (Producer a m) m r
        -- ^
        -> Producer b m r
    folds :: forall (m :: * -> *) x a b r.
    Monad m =>
    (x -> a -> x)
    -> x -> (x -> b) -> FreeT (Producer a m) m r -> Producer b m r
    folds x -> a -> x
    step x
    begin x -> b
    done = FreeT (Proxy X () () a m) m r -> Proxy X () () b m r
    forall {m :: * -> *} {b} {x'} {x}.
    Monad m =>
    FreeT (Proxy X () () a m) m b -> Proxy x' x () b m b
    go
      where
        go :: FreeT (Proxy X () () a m) m b -> Proxy x' x () b m b
    go FreeT (Proxy X () () a m) m b
    f = do
            FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b)
    x <- m (FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b))
    -> Proxy
         x'
         x
         ()
         b
         m
         (FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b))
    forall (m :: * -> *) a. Monad m => m a -> Proxy x' x () b m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (FreeT (Proxy X () () a m) m b
    -> m (FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b))
    forall (f :: * -> *) (m :: * -> *) a.
    FreeT f m a -> m (FreeF f a (FreeT f m a))
    runFreeT FreeT (Proxy X () () a m) m b
    f)
            case FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b)
    x of
                Pure b
    r -> b -> Proxy x' x () b m b
    forall a. a -> Proxy x' x () b m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return b
    r
                Free Proxy X () () a m (FreeT (Proxy X () () a m) m b)
    p -> do
                    (FreeT (Proxy X () () a m) m b
    f', b
    b) <- m (FreeT (Proxy X () () a m) m b, b)
    -> Proxy x' x () b m (FreeT (Proxy X () () a m) m b, b)
    forall (m :: * -> *) a. Monad m => m a -> Proxy x' x () b m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (Proxy X () () a m (FreeT (Proxy X () () a m) m b)
    -> x -> m (FreeT (Proxy X () () a m) m b, b)
    forall {m :: * -> *} {a}.
    Monad m =>
    Producer a m a -> x -> m (a, b)
    fold Proxy X () () a m (FreeT (Proxy X () () a m) m b)
    p x
    begin)
                    b -> Proxy x' x () b m ()
    forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
    yield b
    b
                    FreeT (Proxy X () () a m) m b -> Proxy x' x () b m b
    go FreeT (Proxy X () () a m) m b
    f'

        fold :: Producer a m a -> x -> m (a, b)
    fold Producer a m a
    p x
    x = do
            Either a (a, Producer a m a)
    y <- Producer a m a -> m (Either a (a, Producer a m a))
    forall (m :: * -> *) a r.
    Monad m =>
    Producer a m r -> m (Either r (a, Producer a m r))
    next Producer a m a
    p
            case Either a (a, Producer a m a)
    y of
                Left   a
    f      -> (a, b) -> m (a, b)
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (a
    f, x -> b
    done x
    x)
                Right (a
    a, Producer a m a
    p') -> Producer a m a -> x -> m (a, b)
    fold Producer a m a
    p' (x -> m (a, b)) -> x -> m (a, b)
    forall a b. (a -> b) -> a -> b
    $! x -> a -> x
    step x
    x a
    a
    {-# INLINABLE folds #-}

    {-| Fold each 'Producer' of a 'FreeT', monadically

    @
    'Control.Foldl.impurely' foldsM :: Monad m => 'Control.Foldl.FoldM' a b -> Groups a m r -> 'Producer' b m r
    @
    -}
    foldsM
        :: Monad m
        => (x -> a -> m x)
        -- ^ Step function
        -> m x
        -- ^ Initial accumulator
        -> (x -> m b)
        -- ^ Extraction function
        -> FreeT (Producer a m) m r
        -- ^
        -> Producer b m r
    foldsM :: forall (m :: * -> *) x a b r.
    Monad m =>
    (x -> a -> m x)
    -> m x -> (x -> m b) -> FreeT (Producer a m) m r -> Producer b m r
    foldsM x -> a -> m x
    step m x
    begin x -> m b
    done = FreeT (Proxy X () () a m) m r -> Proxy X () () b m r
    forall {b} {x'} {x}.
    FreeT (Proxy X () () a m) m b -> Proxy x' x () b m b
    go
      where
        go :: FreeT (Proxy X () () a m) m b -> Proxy x' x () b m b
    go FreeT (Proxy X () () a m) m b
    f = do
            FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b)
    y <- m (FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b))
    -> Proxy
         x'
         x
         ()
         b
         m
         (FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b))
    forall (m :: * -> *) a. Monad m => m a -> Proxy x' x () b m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (FreeT (Proxy X () () a m) m b
    -> m (FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b))
    forall (f :: * -> *) (m :: * -> *) a.
    FreeT f m a -> m (FreeF f a (FreeT f m a))
    runFreeT FreeT (Proxy X () () a m) m b
    f)
            case FreeF (Proxy X () () a m) b (FreeT (Proxy X () () a m) m b)
    y of
                Pure b
    r -> b -> Proxy x' x () b m b
    forall a. a -> Proxy x' x () b m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return b
    r
                Free Proxy X () () a m (FreeT (Proxy X () () a m) m b)
    p -> do
                    (FreeT (Proxy X () () a m) m b
    f', b
    b) <- m (FreeT (Proxy X () () a m) m b, b)
    -> Proxy x' x () b m (FreeT (Proxy X () () a m) m b, b)
    forall (m :: * -> *) a. Monad m => m a -> Proxy x' x () b m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m (FreeT (Proxy X () () a m) m b, b)
     -> Proxy x' x () b m (FreeT (Proxy X () () a m) m b, b))
    -> m (FreeT (Proxy X () () a m) m b, b)
    -> Proxy x' x () b m (FreeT (Proxy X () () a m) m b, b)
    forall a b. (a -> b) -> a -> b
    $ do
                        x
    x <- m x
    begin
                        Proxy X () () a m (FreeT (Proxy X () () a m) m b)
    -> x -> m (FreeT (Proxy X () () a m) m b, b)
    forall {a}. Producer a m a -> x -> m (a, b)
    foldM Proxy X () () a m (FreeT (Proxy X () () a m) m b)
    p x
    x
                    b -> Proxy x' x () b m ()
    forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
    yield b
    b
                    FreeT (Proxy X () () a m) m b -> Proxy x' x () b m b
    go FreeT (Proxy X () () a m) m b
    f'

        foldM :: Producer a m a -> x -> m (a, b)
    foldM Producer a m a
    p x
    x = do
            Either a (a, Producer a m a)
    y <- Producer a m a -> m (Either a (a, Producer a m a))
    forall (m :: * -> *) a r.
    Monad m =>
    Producer a m r -> m (Either r (a, Producer a m r))
    next Producer a m a
    p
            case Either a (a, Producer a m a)
    y of
                Left   a
    f      -> do
                    b
    b <- x -> m b
    done x
    x
                    (a, b) -> m (a, b)
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (a
    f, b
    b)
                Right (a
    a, Producer a m a
    p') -> do
                    x
    x' <- x -> a -> m x
    step x
    x a
    a
                    Producer a m a -> x -> m (a, b)
    foldM Producer a m a
    p' (x -> m (a, b)) -> x -> m (a, b)
    forall a b. (a -> b) -> a -> b
    $! x
    x'
    {-# INLINABLE foldsM #-}
    {- $reexports
        "Control.Monad.Trans.Class" re-exports 'lift'.

        "Control.Monad.Trans.Free" re-exports 'FreeF' and 'FreeT'

        "Pipes" re-exports 'Producer', 'yield', and 'next'.
    -}