Copyright | (c) Edward Kmett 2009 |
---|---|

License | BSD3 |

Maintainer | ekmett@gmail.com |

Stability | experimental |

Portability | non-portable (MPTCs) |

Safe Haskell | Trustworthy |

Language | Haskell98 |

## Synopsis

- class Semigroup m => Reducer c m where
- foldMapReduce :: (Foldable f, Monoid m, Reducer e m) => (a -> e) -> f a -> m
- foldMapReduce1 :: (Foldable1 f, Reducer e m) => (a -> e) -> f a -> m
- foldReduce :: (Foldable f, Monoid m, Reducer e m) => f e -> m
- foldReduce1 :: (Foldable1 f, Reducer e m) => f e -> m
- pureUnit :: (Applicative f, Reducer c n) => c -> f n
- returnUnit :: (Monad m, Reducer c n) => c -> m n
- newtype Count = Count {}

# Documentation

class Semigroup m => Reducer c m where Source #

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

is a `Reducer`

m`Semigroup`

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

Minimal definition: `unit`

Convert a value into a `Semigroup`

Append a value to a `Semigroup`

for use in left-to-right reduction

Prepend a value onto a `Semigroup`

for use during right-to-left reduction

## Instances

foldMapReduce1 :: (Foldable1 f, Reducer e m) => (a -> e) -> f a -> m Source #

foldReduce1 :: (Foldable1 f, Reducer e m) => f e -> m Source #

pureUnit :: (Applicative f, Reducer c n) => c -> f n Source #

returnUnit :: (Monad m, Reducer c n) => c -> m n Source #

## Instances

Eq Count Source # | |

Data Count Source # | |

Defined in Data.Semigroup.Reducer gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Count -> c Count # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Count # dataTypeOf :: Count -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Count) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Count) # gmapT :: (forall b. Data b => b -> b) -> Count -> Count # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Count -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Count -> r # gmapQ :: (forall d. Data d => d -> u) -> Count -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Count -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Count -> m Count # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Count -> m Count # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Count -> m Count # | |

Ord Count Source # | |

Read Count Source # | |

Show Count Source # | |

Semigroup Count Source # | |

Monoid Count Source # | |

Hashable Count Source # | |

Defined in Data.Semigroup.Reducer | |

Reducer a Count Source # | |