Description
Combinators for working with Maybe and Either.
Description
Provides many functions for working with Maybe and Either, including canonical fromMaybeM and fromEitherM functions. Please see README.md.
README.md
Control.FromSum
This Haskell module exports the fromEitherM and fromMaybeM convenience functions.
fromMaybeM :: m a -> Maybe a -> m a
fromEitherM :: (e -> m a) -> Either e a -> m a
fromEitherM leftAction eitherValue is the same as either leftAction pure eitherValue.
fromMaybeM nothingAction maybeValue is the same as maybe nothingAction pure maybeValue.
Usage
>>> import Control.FromSum (fromEitherM, fromMaybeM)
>>> fromMaybeM [] $ Just 5
[5]
>>> fromMaybeM [] Nothing
[]
>>> fromEitherM (\s -> [length s]) $ Right 5
[5]
>>> fromEitherM (\s -> [length s]) $ Left "foo"
[3]