sum package:protolude

The sum function computes the sum of the numbers of a structure.

Examples

Basic usage:
>>> sum []
0
>>> sum [42]
42
>>> sum [1..10]
55
>>> sum [4.1, 2.0, 1.7]
7.8
>>> sum [1..]
* Hangs forever *
The sum of a collection of actions using (<|>), generalizing concat. asum is just like msum, but generalised to Alternative.

Examples

Basic usage:
>>> asum [Just "Hello", Nothing, Just "World"]
Just "Hello"
The sum of a collection of actions using (<|>), generalizing concat. msum is just like asum, but specialised to MonadPlus.

Examples

Basic usage, using the MonadPlus instance for Maybe:
>>> msum [Just "Hello", Nothing, Just "World"]
Just "Hello"