bos/attoparsec — Issue #8: Generalise scan to scanEither
Author: reinerp
Created: 2012-01-21 05:14:32+00:00
State: open

The `scan` parser has type

scan :: s -> (s -> Word8 -> Maybe s) -> Parser ByteString

Sometimes it can be useful to know the state machine's final state, but `scan` doesn't expose this. I would like to see a generalisation of `scan` to a function

scanEither :: s -> (s -> Word8 -> Either s r) -> Parser (ByteString, Either s r)

which returns the state machine's final state. Then `scan` could be implemented in terms of `scanEither` as

scan s0 p = fst <$> scanEither s0 p'
where
p' s w = case p s w of
Just s' -> Left s'
Nothing -> Right ()