HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulepipes-group-1.0.12Haskell2010

Pipes.Group

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
  • 3 types
  • 15 values

Lenses

4 declarations
valuegroups :: (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)
#

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
Example4 expressions
import Lens.Family (view)import Pipes (yield, each)import Pipes.Prelude (toList)(toList . intercalates (yield '|') . view groups) (each "12233345")"1|22|333|4|5"
valuegroupsBy
  1. :: Monad m
  2. => a' -> a' -> Bool
  3. -> Lens (Producer a' m x) (Producer a m x) (FreeT (Producer a' m) m x) (FreeT (Producer a m) m x)
#

groupsBy splits a Producer into a FreeT of Producers 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
Example4 expressions
import Lens.Family (view)import Pipes (yield, each)import Pipes.Prelude (toList)(toList . intercalates (yield '|') . view (groupsBy (==))) (each "12233345")"1|22|333|4|5"
valuegroupsBy'
  1. :: Monad m
  2. => a' -> a' -> Bool
  3. -> Lens (Producer a' m x) (Producer a m x) (FreeT (Producer a' m) m x) (FreeT (Producer a m) m x)
#

groupsBy' splits a Producer into a FreeT of Producers 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

Example6 expressions
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
valuechunksOf
  1. :: Monad m
  2. => Int
  3. -> Lens (Producer a' m x) (Producer a m x) (FreeT (Producer a' m) m x) (FreeT (Producer a m) m x)
#

chunksOf is an splits a Producer into a FreeT of Producers 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
Example4 expressions
import Lens.Family (view)import Pipes (yield, each)import Pipes.Prelude (toList)(toList . intercalates (yield '|') . view (chunksOf 3)) (each "12233345")"122|333|45"

Transformations

5 declarations
valuetakes :: (Functor f, Monad m) => Int -> FreeT f m () -> FreeT f m ()
#

(takes n) only keeps the first n functor layers of a FreeT

takes :: Monad m => Int -> Groups a m () -> Groups a m ()
Example4 expressions
import Lens.Family (view)import Pipes (yield, each)import Pipes.Prelude (toList)(toList . intercalates (yield '|') . takes 3 . view groups) (each "12233345")"1|22|333"
valuedrops
  1. :: Monad m
  2. => Int
  3. -> FreeT (Producer a m) m x
  4. -> FreeT (Producer a m) m x
#

(drops n) peels off the first n Producer layers of a FreeT

drops :: Monad m => Int -> Transformation a m x
Example4 expressions
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.

valuemaps
  1. :: (Monad m, Functor g)
  2. => forall r. f r -> g r
  3. -> FreeT f m x
  4. -> FreeT g m x
#

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 transFreeT

valueindividually :: (Monad m, Functor g) => Setter (FreeT f m x) (FreeT g m x) (f (FreeT f m x)) (g (FreeT f m x))
#

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

Joiners

2 declarations

Folds

2 declarations

These folds are designed to be compatible with the foldl library. See the purely and 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)
valuefoldsM
  1. :: Monad m
  2. => (x -> a -> m x)

    Step function

  3. -> m x

    Initial accumulator

  4. -> (x -> m b)

    Extraction function

  5. -> FreeT (Producer a m) m r
  6. -> Producer b m r
#

Fold each Producer of a FreeT, monadically

impurely foldsM :: Monad m => FoldM a b -> Groups a m r -> Producer b m r

Re-exports

6 declarations
methodlift :: Monad m => m a -> t m a
#

Lift a computation from the argument monad to the constructed monad.

datadata FreeF (f :: Type -> Type) a b
#

The base functor for a free monad.

Constructors

Instances23Generic1, Bifoldable, Bifunctor, Bitraversable, Eq2, Ord2, …
newtypenewtype FreeT (f :: Type -> Type) (m :: Type -> Type) a
#

The "free monad transformer" for a functor f

Constructors

Instances29MonadError, MonadReader, MonadState, MonadWriter, MonadBase, MonadFree, …