# Maybe -package -base

The MaybeT monad transformer adds the ability to fail to a monad. A sequence of actions succeeds, producing a value, only if all the actions in the sequence are successful. If one fails, the rest of the sequence is skipped and the composite action fails. For a variant allowing a range of error values, see Control.Monad.Trans.Error.
The parameterizable maybe monad, obtained by composing an arbitrary monad with the Maybe monad. Computations are actions that may produce a value or fail. The return function yields a successful computation, while >>= sequences two subcomputations, failing on the first error.
O(n). Map values and collect the Just results. > let f x = if x == "a" then Just "new a" else Nothing > mapMaybe f (fromList [(5,"a"), (3,"b")]) == singleton 5 "new a"
O(n). Map values and collect the Just results. > let f x = if x == "a" then Just "new a" else Nothing > mapMaybe f (fromList [(5,"a"), (3,"b")]) == singleton 5 "new a"
Transform the computation inside a MaybeT. *  (mapMaybeT f m) = f (runMaybeT >
O(n). Map keys/values and collect the Just results. > let f k _ = if k < 5 then Just ("key (:) " ++ (show k)) else Nothing > mapMaybeWithKey f (fromList [(5,"a"), (3,"b")]) == singleton 3 "key (:) 3"
O(n). Map keys/values and collect the Just results. > let f k _ = if k < 5 then Just ("key (:) " ++ (show k)) else Nothing > mapMaybeWithKey f (fromList [(5,"a"), (3,"b")]) == singleton 3 "key (:) 3"
optionMaybe p tries to apply parser p. If p fails without consuming input, it return Nothing, otherwise it returns Just the value returned by p.
Tries to generate a value that satisfies a predicate.