Portability | non-portable (MPTCs) |
---|---|

Stability | experimental |

Maintainer | ekmett@gmail.com |

Safe Haskell | None |

- class Monoid m => Reducer c m where
- foldMapReduce :: (Foldable f, e `Reducer` m) => (a -> e) -> f a -> m
- foldReduce :: (Foldable f, e `Reducer` m) => f e -> m
- pureUnit :: (Applicative f, c `Reducer` n) => c -> f n
- returnUnit :: (Monad m, c `Reducer` n) => c -> m n

# Documentation

class Monoid m => Reducer c m whereSource

This type may be best read infix. A `c `

is a `Reducer`

m`Monoid`

`m`

that maps
values of type `c`

through `unit`

to values of type `m`

. A `c`

-`Reducer`

may also
supply operations which tack-on another `c`

to an existing `Monoid`

`m`

on the left
or right. These specialized reductions may be more efficient in some scenarios
and are used when appropriate by a `Generator`

. The names `cons`

and `snoc`

work
by analogy to the synonymous operations in the list monoid.

This class deliberately avoids functional-dependencies, so that () can be a `c`

-Reducer
for all `c`

, and so many common reducers can work over multiple types, for instance,
First and Last may reduce both `a`

and `Maybe`

`a`

. Since a `Generator`

has a fixed element
type, the input to the reducer is generally known and extracting from the monoid usually
is sufficient to fix the result type. Combinators are available for most scenarios where
this is not the case, and the few remaining cases can be handled by using an explicit
type annotation.

Convert a value into a `Monoid`

Append a value to a `Monoid`

for use in left-to-right reduction

Prepend a value onto a `Monoid`

for use during right-to-left reduction

foldMapReduce :: (Foldable f, e `Reducer` m) => (a -> e) -> f a -> mSource

foldReduce :: (Foldable f, e `Reducer` m) => f e -> mSource

pureUnit :: (Applicative f, c `Reducer` n) => c -> f nSource

returnUnit :: (Monad m, c `Reducer` n) => c -> m nSource