Using a function to signal group changes, run a machine independently over each group with the value returned provided.
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
Using a function to signal group changes, run a machine independently over each group.
Run a machine repeatedly over n-element segments of the stream, providing
an incrementing value to each run.
Tagging a stream
8 declarationsMark a transition point between two groups when a state passing function returns a Just i. Examples
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]
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
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]
Mark a transition point between two groups as a function of adjacent elements, and insert the value returned as the separator. Examples
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]
Mark a transition point between two groups using an action on adjacent elements, and insert the value returned as the separator. Examples
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]
Mark a transition point between two groups as a function of adjacent elements. Examples
runT $ supply [1,2,2] (taggedOn_ (==))[Right 1,Left (),Right 2,Right 2]
Mark a transition point between two groups at every n values, stepping
the separator by a function.
Examples
runT $ supply [1..5] (taggedAt 2 True not)[Right 1,Right 2,Left True,Right 3,Right 4,Left False,Right 5]
Mark a transition point between two groups at every n values.
Examples
runT $ supply [1..5] (taggedAt_ 2)[Right 1,Right 2,Left (),Right 3,Right 4,Left (),Right 5]
Mark a transition point between two groups at every n values, using the
counter as the separator.
Examples
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 declarationsRun a machine multiple times over partitions of the input stream specified
by Left i values, passing the is to each MachineT run.
Examples
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)]
Run a machine multiple times over partitions of the input stream specified by Left () values. Examples
let input = [Right 1,Left (),Right 3,Right 4,Left ()]runT $ supply input (partitioning_ (fold (flip (:)) []))[[1],[4,3],[]]
Helpers
2 declarationsRun a machine with no input until it stops, then behave as another machine.
Read inputs until a condition is met, then behave as cont with input matching condition as first input of cont. If await fails, stop.