Safe Haskell | None |
---|---|

Language | Haskell98 |

- See the Data.Repa.Vector.Unboxed module for examples of how these functions can be used.

- compactS :: Monad m => (s -> a -> (s, Maybe b)) -> s -> Stream m a -> Stream m b
- compactInS :: Monad m => (a -> a -> (a, Maybe a)) -> Stream m a -> Stream m a
- catMaybesS :: Monad m => Stream m (Maybe a) -> Stream m a
- diceSepS :: Monad m => (a -> Bool) -> (a -> Bool) -> Stream m a -> Stream m (Maybe (Int, Int), Maybe (Int, Int))
- extractS :: Monad m => (Int -> a) -> Stream m (Int, Int) -> Stream m a
- insertS :: Monad m => (Int -> Maybe a) -> Stream m a -> Stream m a
- mergeS :: (Monad m, Ord k) => (k -> a -> b -> c) -> (k -> a -> c) -> (k -> b -> c) -> Stream m (k, a) -> Stream m (k, b) -> Stream m (k, c)
- padForwardS :: (Monad m, Ord k) => (k -> k) -> Stream m (k, v) -> Stream m (k, v)
- unsafeRatchetS :: (MVector vm Int, Vector vv Int) => vm (PrimState IO) Int -> vv Int -> IORef (vm (PrimState IO) Int) -> Stream IO Int
- replicatesS :: Monad m => Stream m (Int, a) -> Stream m a
- findSegmentsS :: Monad m => (a -> Bool) -> (a -> Bool) -> i -> Stream m (i, a) -> Stream m (i, i)
- startLengthsOfSegsS :: Monad m => Stream m (Int, Int) -> Stream m (Int, Int)

# Compacting

:: Monad m | |

=> (s -> a -> (s, Maybe b)) | Worker function. |

-> s | Starting state |

-> Stream m a | Input elements. |

-> Stream m b |

Combination of `fold`

and `filter`

.

We walk over the stream front to back, maintaining an accumulator. At each point we can chose to emit an element (or not)

Like `compact`

but use the first value of the stream as the
initial state, and add the final state to the end of the output.

# Concatenating

# Dicing

:: Monad m | |

=> (a -> Bool) | Detect the end of a column. |

-> (a -> Bool) | Detect the end of a row. |

-> Stream m a | |

-> Stream m (Maybe (Int, Int), Maybe (Int, Int)) | Segment starts and lengths |

Given predicates that detect the begining and end of interesting segments of information, scan through a vector looking for when these begin and end.

# Extracting

:: Monad m | |

=> (Int -> a) | Function to get elements from the source. |

-> Stream m (Int, Int) | Segment start positions and lengths. |

-> Stream m a | Result elements. |

Extract segments from some source array and concatenate them.

# Inserting

:: Monad m | |

=> (Int -> Maybe a) | Produce a new element for this index. |

-> Stream m a | Source stream. |

-> Stream m a |

Insert elements produced by the given function in to a stream.

# Merging

:: (Monad m, Ord k) | |

=> (k -> a -> b -> c) | Combine two values with the same key. |

-> (k -> a -> c) | Handle a left value without a right value. |

-> (k -> b -> c) | Handle a right value without a left value. |

-> Stream m (k, a) | Stream of keys and left values. |

-> Stream m (k, b) | Stream of keys and right values. |

-> Stream m (k, c) | Stream of keys and results. |

Merge two key-value streams.

The streams are assumed to be pre-sorted on the keys.

# Padding

:: (Monad m, Ord k) | |

=> (k -> k) | Successor functinon for keys. |

-> Stream m (k, v) | Input stream. |

-> Stream m (k, v) |

Given a stream of keys and values, and a successor function for keys, if the stream is has keys missing in the sequence then insert the missing key, copying forward the the previous value.

# Ratcheting

:: (MVector vm Int, Vector vv Int) | |

=> vm (PrimState IO) Int | Starting values. Overwritten duing computation. |

-> vv Int | Ending values |

-> IORef (vm (PrimState IO) Int) | Vector holding segment lengths. |

-> Stream IO Int |

Interleaved `enumFromTo`

.

Given a vector of starting values, and a vector of stopping values, produce an stream of elements where we increase each of the starting values to the stopping values in a round-robin order. Also produce a vector of result segment lengths.

unsafeRatchetS [10,20,30,40] [15,26,33,47] = [10,20,30,40 -- 4 ,11,21,31,41 -- 4 ,12,22,32,42 -- 4 ,13,23 ,43 -- 3 ,14,24 ,44 -- 3 ,25 ,45 -- 2 ,46] -- 1 ^^^^ ^^^ Elements Lengths

The function takes the starting values in a mutable vector and updates it during computation. Computation proceeds by making passes through the mutable vector and updating the starting values until they match the stopping values.

UNSAFE: Both input vectors must have the same length, but this is not checked.

# Replicating

replicatesS :: Monad m => Stream m (Int, a) -> Stream m a Source

Segmented replicate.

Given a stream of counts and values, produce a result stream where each value is replciated the associated number of times.

# Segmenting

:: Monad m | |

=> (a -> Bool) | Predicate to check for start of segment. |

-> (a -> Bool) | Predicate to check for end of segment. |

-> i | Index of final element in stream. |

-> Stream m (i, a) | Stream of indices and elements. |

-> Stream m (i, i) | Stream of segment start and end indices. |

Given predicates that detect the beginning and end of some interesting segment of information, scan through a vector looking for when these segments begin and end.

:: Monad m | |

=> Stream m (Int, Int) | Start and end indices. |

-> Stream m (Int, Int) | Start indices and lengths of segments. |

Given a stream of starting and ending indices for some segments, convert it to a stream of starting indices and segment lengths.

- The ending indices must be after the starting indices, otherwise the result will contain negative lengths.