from-sum

Canonical fromMaybeM and fromEitherM functions.

https://github.com/cdepillabout/from-sum

Version on this page:0.1.2.0
LTS Haskell 22.19:0.2.3.0
Stackage Nightly 2024-05-01:0.2.3.0
Latest on Hackage:0.2.3.0

See all snapshots from-sum appears in

BSD-3-Clause licensed by Dennis Gosnell
Maintained by [email protected]
This version can be pinned in stack with:from-sum-0.1.2.0@sha256:dcd5fc1622c84b30acd9a02e64a651219732ee7c1958db932df3511d84b7cc15,1119

Module documentation for 0.1.2.0

Depends on 1 package(full list with versions):

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]