Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Stream monads.
By stream, I mean a container indexed by the naturals(/integers). Note that not all parts of streampatch are limited to this, but it's an extremely useful invariant, without which patch linearization & application gets a whole lot more complex. So for now, streams it is.
These are designed to support easy pure and impure implementations. That's the reasoning behind forward-only streams, and separating overwrites (easy impure, mid pure) from inserts (hard impure, ease pure).
Documentation
class Monad m => FwdInplaceStream m where Source #
Streams supporting forward seeking and in-place edits (length never changes).
readahead :: Index m -> m (Chunk m) Source #
Read a number of elements forward without moving the cursor.
Argument must be positive.
overwrite :: Chunk m -> m () Source #
Overlay a chunk onto the stream at the current cursor position, overwriting existing elements.
Moves the cursor to the right by the length of the chunk.
advance :: Index m -> m () Source #
Move cursor forwards without reading. Must be positive.
getCursor :: m (Index m) Source #
Get the current cursor position.
Intended for error messages.
Instances
class FwdInplaceStream m => FwdStream m where Source #
Streams supporting forward seeking and arbitrary edits.
write :: Chunk m -> m () Source #
Write a chunk into the stream at the current cursor position.
Moves the cursor to the right by the length of the chunk.
delete :: Index m -> m () Source #
Delete a sized chunk at the current cursor position.
Argument must be positive.
Instances
Monad m => FwdStream (StateT (ByteString, Builder, Int) m) Source # | |
Defined in StreamPatch.Stream |