HORIZON HASKELLDocslts/ghc-9.14.xd82dee82026-10-12Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · d82dee8 · 2026-10-12

Modulemachines-0.7.4Haskell2010

Data.Machine.Group.General

Split up input streams into groups with separator values and process the groups with their own MachineT.

  • 15 values
  • Packagemachines-0.7.4
  • Exports15
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceGeneral.hs
valuegroupingOn
  1. :: Monad m
  2. => i
  3. -> a -> a -> Maybe i
  4. -> i -> ProcessT m a b
  5. -> ProcessT m a b
#

Using a function to signal group changes, run a machine independently over each group with the value returned provided.

valuegroupingN :: Monad m => Int -> (Int -> ProcessT m a b) -> ProcessT m a b
#

Run a machine repeatedly over n-element segments of the stream, providing an incrementing value to each run.

Tagging a stream

8 declarations
valuetaggedState
  1. :: Monad m
  2. => s
  3. -> a -> s -> (Maybe i, s)
  4. -> ProcessT m a (Either i a)
#

Mark a transition point between two groups when a state passing function returns a Just i. Examples

Example1 expression
runT $ supply [1,3,3,2] (taggedState (-1) (\x y -> (even x <$ guard (x /= y), x)))[Left False,Right 1,Left False,Right 3,Right 3,Left True,Right 2]
valuetaggedM :: Monad m => (a -> m (Maybe i)) -> ProcessT m a (Either i a)
#

Mark a transition point between two groups when an action returns a Just i. Could be useful for breaking up a stream based on time passed. Examples

Example2 expressions
let f x = do{ y <- ask; return (even x <$ guard (x > y)) }flip runReader 1 . runT $ supply [1,3,3,2] (taggedM f)[Right 1,Left False,Right 3,Left False,Right 3,Left True,Right 2]
valuetaggedOn :: Monad m => (a -> a -> Maybe i) -> ProcessT m a (Either i a)
#

Mark a transition point between two groups as a function of adjacent elements, and insert the value returned as the separator. Examples

Example1 expression
runT $ supply [1,3,3,2] (taggedOn (\x y -> (x < y) <$ guard (x /= y)))[Right 1,Left True,Right 3,Right 3,Left False,Right 2]
valuetaggedOnM :: Monad m => (a -> a -> m (Maybe i)) -> ProcessT m a (Either i a)
#

Mark a transition point between two groups using an action on adjacent elements, and insert the value returned as the separator. Examples

Example2 expressions
let f x y = do{ z <- ask; return ((x + y <$ guard (z < x + y))) }flip runReader 5 . runT $ supply [1..5] (taggedOnM f)[Right 1,Right 2,Right 3,Left 7,Right 4,Left 9,Right 5]
valuetaggedOn_ :: Monad m => (a -> a -> Bool) -> ProcessT m a (Either () a)
#

Mark a transition point between two groups as a function of adjacent elements. Examples

Example1 expression
runT $ supply [1,2,2] (taggedOn_ (==))[Right 1,Left (),Right 2,Right 2]
valuetaggedAt :: Monad m => Int -> s -> (s -> s) -> ProcessT m a (Either s a)
#

Mark a transition point between two groups at every n values, stepping the separator by a function. Examples

Example1 expression
runT $ supply [1..5] (taggedAt 2 True not)[Right 1,Right 2,Left True,Right 3,Right 4,Left False,Right 5]
valuetaggedAt_ :: Monad m => Int -> ProcessT m a (Either () a)
#

Mark a transition point between two groups at every n values. Examples

Example1 expression
runT $ supply [1..5] (taggedAt_ 2)[Right 1,Right 2,Left (),Right 3,Right 4,Left (),Right 5]
valuetaggedCount :: Monad m => Int -> ProcessT m a (Either Int a)
#

Mark a transition point between two groups at every n values, using the counter as the separator. Examples

Example1 expression
runT $ supply [1..5] (taggedCount 2)[Right 1,Right 2,Left 1,Right 3,Right 4,Left 2,Right 5]

Reset a machine for each group

2 declarations
valuepartitioning
  1. :: Monad m
  2. => i
  3. -> i -> ProcessT m a b
  4. -> ProcessT m (Either i a) b
#

Run a machine multiple times over partitions of the input stream specified by Left i values, passing the is to each MachineT run. Examples

Example2 expressions
let input = [Right 1, Right 2,Left 1, Right 3,Left 2, Right 4]runT $ supply input (partitioning 0 (\x -> mapping (\y -> (x,y))))[(0,1),(0,2),(1,3),(2,4)]
valuepartitioning_ :: Monad m => ProcessT m a b -> ProcessT m (Either () a) b
#

Run a machine multiple times over partitions of the input stream specified by Left () values. Examples

Example2 expressions
let input = [Right 1,Left (),Right 3,Right 4,Left ()]runT $ supply input (partitioning_ (fold (flip (:)) []))[[1],[4,3],[]]

Helpers

2 declarations
valueawaitUntil
  1. :: Monad m
  2. => a -> Bool
  3. -> a -> ProcessT m a b
  4. -> ProcessT m a b
#

Read inputs until a condition is met, then behave as cont with input matching condition as first input of cont. If await fails, stop.