option package:parsers

option x p tries to apply parser p. If p fails without consuming input, it returns the value x, otherwise the value returned by p.
priority = option 0 (digitToInt <$> digit)
One or none. It is useful for modelling any computation that is allowed to fail.

Examples

Using the Alternative instance of Control.Monad.Except, the following functions:
>>> import Control.Monad.Except
>>> canFail = throwError "it failed" :: Except String Int

>>> final = return 42                :: Except String Int
Can be combined by allowing the first function to fail:
>>> runExcept $ canFail *> final
Left "it failed"

>>> runExcept $ optional canFail *> final
Right 42
skipOptional p tries to apply parser p. It will parse p or nothing. It only fails if p fails after consuming input. It discards the result of p. (Plays the role of parsec's optional, which conflicts with Applicative's optional)