from-sum

Canonical fromMaybeM and fromEitherM functions. https://github.com/cdepillabout/from-sum

Version on this page:0.2.1.0
LTS Haskell 8.12:0.2.1.0
Stackage Nightly 2017-04-28:0.2.1.0
Latest on Hackage:0.2.1.0
BSD3 licensed by Dennis Gosnell
Maintained by cdep.illabout@gmail.com

Module documentation for 0.2.1.0

Control.FromSum

Build Status Hackage Stackage LTS Stackage Nightly

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]
Depends on:
Used by 1 package:
comments powered byDisqus