reducers-3.10.1.1: Semigroups, specialized containers and a general map/reduce framework

Portability | non-portable (MPTCs)
Stability | experimental
Maintainer | ekmett@gmail.com
Safe Haskell | Trustworthy

Data.Semigroup.Reducer

Description

A `c`-`Reducer` is a `Semigroup` with a canonical mapping from `c` to the Semigroup.

Synopsis

- class Semigroup m => Reducer c m where
  - unit :: c -> m
  - snoc :: m -> c -> m
  - cons :: c -> m -> m
- 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 {
  - getCount :: Int
  }

# Documentation

class Semigroup m => Reducer c m where Source

This type may be best read infix. A `c `Reducer` m` is a `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`

Methods

unit :: c -> mSource

Convert a value into a `Semigroup`

snoc :: m -> c -> mSource

Append a value to a `Semigroup` for use in left-to-right reduction

cons :: c -> m -> mSource

Prepend a value onto a `Semigroup` for use during right-to-left reduction

Instances

Reducer Bool All |
Reducer Bool Any |
Reducer Int IntSet |
Reducer c () |
Reducer a Count |
Monoid m => Reducer m (WrappedMonoid m) |
Ord a => Reducer a (Set a) |
Reducer a (Seq a) |
Reducer a (Last a) |
Reducer a (First a) |
Ord a => Reducer a (Max a) |
Ord a => Reducer a (Min a) |
Num a => Reducer a (Product a) |
Num a => Reducer a (Sum a) |
Semigroup a => Reducer a (Dual a) |
Reducer c [c] |
HasUnion f => Reducer f (Union f) |
Semigroup m => Reducer m (Self m) |
Measured v a => Reducer a (FingerTree v a) |
(Reducer c m, Reducer c n) => Reducer c (m, n) |
(Reducer c m, Reducer c n, Reducer c o) => Reducer c (m, n, o) |
(Reducer c m, Reducer c n, Reducer c o, Reducer c p) => Reducer c (m, n, o, p) |
Applicative f => Reducer (f a) (Traversal f) |
Monad f => Reducer (f a) (Action f) |
Apply f => Reducer (f a) (Trav f) |
Reducer (Maybe a) (Last a) |
Reducer (Maybe a) (First a) |
(Applicative f, Reducer c m) => Reducer (f c) (Ap f m) |
Alternative f => Reducer (f a) (Alternate f a) |
(Monad f, Reducer c m) => Reducer (f c) (Mon f m) |
MonadPlus f => Reducer (f a) (MonadSum f a) |
(HasUnionWith f, Semigroup m, Monoid m) => Reducer (f m) (UnionWith f m) |
(Apply f, Reducer c m) => Reducer (f c) (App f m) |
Alt f => Reducer (f a) (Alter f a) |
Reducer c m => Reducer (WithReducer m c) m |
Reducer (a -> a) (Endo a) |
Reducer (Int, v) (IntMap v) |
Ord k => Reducer (k, v) (Map k v) |

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

Apply a `Reducer` to a `Foldable` container, after mapping the contents into a suitable form for reduction.

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

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

Apply a `Reducer` to a `Foldable` mapping each element through `unit`

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

Apply a `Reducer` to a `Foldable1` mapping each element through `unit`

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

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

newtype Count Source

Constructors

Count |

Fields

getCount :: Int

Instances

Eq Count |
Data Count |
Ord Count |
Read Count |
Show Count |
Typeable Count |
Monoid Count |
Hashable Count |
Semigroup Count |
Reducer a Count |