seqid-streams-0.6.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

-> (SequenceIdError -> 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 (SequenceIdError {errType = SequenceIdDropped, lastSeqId = 0, currSeqId = 5})

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

sequenceIdOutputStream Source #

Arguments

:: SequenceId

Initial sequence ID

-> (SequenceId -> a -> b)

Transformation function

-> OutputStream b

OutputStream to count the elements of

-> IO (OutputStream a)

(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'