seqid-streams-0.1.0: Sequence ID IO-Streams

Safe HaskellNone
LanguageHaskell2010

System.IO.Streams.SequenceId

Synopsis

Documentation

sequenceIdInputStream Source

Arguments

:: SequenceId

Initial sequence ID

-> (a -> SequenceId)

Function applied to each element of the stream to get the sequence ID

-> (SequenceError -> IO ())

Error handler

-> InputStream a

InputStream to check the sequence of

-> IO (InputStream a)

Pass-through of the given stream

Wrap an InputStream and check for dropped or duplicated sequence IDs.

Example:

ghci> fromList [1..10 :: SequenceId] >>= sequenceIdInputStream 0 id (fail . show) >>= toList
[1,2,3,4,5,6,7,8,9,10]

ghci> fromList [5..10 :: SequenceId] >>= sequenceIdInputStream 0 id (fail . show) >>= toList
*** Exception: user error (SequenceIdDropped (SequenceIds {lastSeqId = 0, currSeqId = 5}))

ghci> fromList [5..10 :: SequenceId] >>= sequenceIdInputStream 1 id (fail . show) >>= toList
*** Exception: user error (SequenceIdDuplicated (SequenceIds {lastSeqId = 1, currSeqId = 1}))

sequenceIdOutputStream Source

Arguments

:: SequenceId

Initial sequence ID

-> OutputStream a

OutputStream to count the elements of

-> IO (OutputStream a, IO SequenceId)

(IO SequenceId) is the action to run to get the current sequence ID

Wrap an OutputStream to give a sequence ID for each element written.

Example:

(outStream', getSeqId) <- sequenceIdOutputStream 1 outStream
return $ contramapM (addSeqId getSeqId) outStream'