File: README.md

package info (click to toggle)
haskell-from-sum 0.2.3.0-4
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 108 kB
  • sloc: haskell: 170; makefile: 6
file content (38 lines) | stat: -rw-r--r-- 1,165 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

Control.FromSum
===============

[![Build Status](https://secure.travis-ci.org/cdepillabout/from-sum.svg)](http://travis-ci.org/cdepillabout/from-sum)
[![Hackage](https://img.shields.io/hackage/v/from-sum.svg)](https://hackage.haskell.org/package/from-sum)
[![Stackage LTS](http://stackage.org/package/from-sum/badge/lts)](http://stackage.org/lts/package/from-sum)
[![Stackage Nightly](http://stackage.org/package/from-sum/badge/nightly)](http://stackage.org/nightly/package/from-sum)
![BSD3 license](https://img.shields.io/badge/license-BSD3-blue.svg)

This Haskell module exports the `fromEitherM` and `fromMaybeM` convenience
functions.

```haskell
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

```haskell
>>> 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]
```