Generalise scan to scanEither #8

Closed
reinerp opened this Issue Jan 21, 2012 · 0 comments

1 participant

@reinerp

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 ()
@bos bos added a commit that referenced this issue Feb 15, 2014
@bos Generalize scan on ByteString to runScanner
The name is by analogy to State.

The issue is gh-8.

--HG--
extra : amend_source : a1245546da829cb23416074cfbe613e7fbb7b31d
4624b0b
@bos bos added a commit that closed this issue Feb 15, 2014
@bos Generalize scan on Text to runScanner
The name is by analogy to State.

This fixes gh-8.
98339a8
@bos bos closed this in 98339a8 Feb 15, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment