bytepatch-0.4.1: Patch byte-representable data in a bytestream
Safe HaskellSafe-Inferred
LanguageGHC2021

StreamPatch.Stream

Description

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).

Synopsis

Documentation

class Monad m => FwdInplaceStream m where Source #

Streams supporting forward seeking and in-place edits (length never changes).

Associated Types

type Chunk m :: Type Source #

type Index m :: Type Source #

The unsigned integral type used for indexing. Int has a sign, but is often used internally; Integer also gets some use; Natural is the most mathematically honest. I leave the decision up to the instance to allow them to be as efficient as possible.

Methods

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

Instances details
MonadIO m => FwdInplaceStream (ReaderT Handle m) Source # 
Instance details

Defined in StreamPatch.Stream

Associated Types

type Chunk (ReaderT Handle m) Source #

type Index (ReaderT Handle m) Source #

Monad m => FwdInplaceStream (StateT (ByteString, Builder, Int) m) Source # 
Instance details

Defined in StreamPatch.Stream

Associated Types

type Chunk (StateT (ByteString, Builder, Int) m) Source #

type Index (StateT (ByteString, Builder, Int) m) Source #

Monad m => FwdInplaceStream (StateT ([a], [a], Int) m) Source # 
Instance details

Defined in StreamPatch.Stream

Associated Types

type Chunk (StateT ([a], [a], Int) m) Source #

type Index (StateT ([a], [a], Int) m) Source #

Methods

readahead :: Index (StateT ([a], [a], Int) m) -> StateT ([a], [a], Int) m (Chunk (StateT ([a], [a], Int) m)) Source #

overwrite :: Chunk (StateT ([a], [a], Int) m) -> StateT ([a], [a], Int) m () Source #

advance :: Index (StateT ([a], [a], Int) m) -> StateT ([a], [a], Int) m () Source #

getCursor :: StateT ([a], [a], Int) m (Index (StateT ([a], [a], Int) m)) Source #

class FwdInplaceStream m => FwdStream m where Source #

Streams supporting forward seeking and arbitrary edits.

Methods

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

Instances details
Monad m => FwdStream (StateT (ByteString, Builder, Int) m) Source # 
Instance details

Defined in StreamPatch.Stream