sum package:relude

Stricter version of sum.
>>> sum [1..10]
55
Monoid under addition.
Sum a <> Sum b = Sum (a + b)

Examples

>>> Sum 1 <> Sum 2 <> mempty
Sum {getSum = 3}
>>> mconcat [ Sum n | n <- [3 .. 9]]
Sum {getSum = 42}
Alternative version of asum that takes a function to map over.
>>> asumMap (\x -> if x > 2 then Just x else Nothing) [1..4]
Just 3
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, generalizing biconcat.

Examples

Basic usage:
>>> biasum (Nothing, Nothing)
Nothing
>>> biasum (Nothing, Just 42)
Just 42
>>> biasum (Just 18, Nothing)
Just 18
>>> biasum (Just 18, Just 42)
Just 18