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

Copyright | (c) Edward Kmett 2009
License | BSD-style
Maintainer | ekmett@gmail.com
Stability | experimental
Portability | non-portable (type families, MPTCs)
Safe Haskell | Safe
Language | Haskell98

Data.Generator.Combinators

Contents

- Monadic Reduction
- Applicative Reduction
- Logical Reduction
- Monoidal Reduction
- List-Like Reduction

Description

Utilities for working with Monoids that conflict with names from the Prelude, Data.Foldable, Control.Monad or elsewhere. Intended to be imported qualified.

    import Data.Generator.Combinators as Generator

Synopsis

- mapM_ :: (Generator c, Monad m) => (Elem c -> m b) -> c -> m ()
- forM_ :: (Generator c, Monad m) => c -> (Elem c -> m b) -> m ()
- msum :: (Generator c, MonadPlus m, m a ~ Elem c) => c -> m a
- traverse_ :: (Generator c, Applicative f) => (Elem c -> f b) -> c -> f ()
- for_ :: (Generator c, Applicative f) => c -> (Elem c -> f b) -> f ()
- asum :: (Generator c, Alternative f, f a ~ Elem c) => c -> f a
- and :: (Generator c, Elem c ~ Bool) => c -> Bool
- or :: (Generator c, Elem c ~ Bool) => c -> Bool
- any :: Generator c => (Elem c -> Bool) -> c -> Bool
- all :: Generator c => (Elem c -> Bool) -> c -> Bool
- foldMap :: (Monoid m, Generator c) => (Elem c -> m) -> c -> m
- fold :: (Monoid m, Generator c, Elem c ~ m) => c -> m
- toList :: Generator c => c -> [Elem c]
- concatMap :: Generator c => (Elem c -> [b]) -> c -> [b]
- elem :: (Generator c, Eq (Elem c)) => Elem c -> c -> Bool
- filter :: (Generator c, Reducer (Elem c) m, Monoid m) => (Elem c -> Bool) -> c -> m
- filterWith :: (Generator c, Reducer (Elem c) m, Monoid m) => (m -> n) -> (Elem c -> Bool) -> c -> n
- sum :: (Generator c, Num (Elem c)) => c -> Elem c
- product :: (Generator c, Num (Elem c)) => c -> Elem c
- notElem :: (Generator c, Eq (Elem c)) => Elem c -> c -> Bool

# Monadic Reduction

mapM_ :: (Generator c, Monad m) => (Elem c -> m b) -> c -> m () #

Efficiently `mapReduce` a `Generator` using the `Action` monoid. A specialized version of its namesake from Data.Foldable and Control.Monad

       mapReduceWith getAction

forM_ :: (Generator c, Monad m) => c -> (Elem c -> m b) -> m () #

Convenience function as found in Data.Foldable and Control.Monad

        flip mapM_

msum :: (Generator c, MonadPlus m, m a ~ Elem c) => c -> m a #

The sum of a collection of actions, generalizing `concat`

        reduceWith getMonadSum

# Applicative Reduction

traverse_ :: (Generator c, Applicative f) => (Elem c -> f b) -> c -> f () #

Efficiently `mapReduce` a `Generator` using the `Traversal` monoid. A specialized version of its namesake from Data.Foldable

        mapReduce getTraversal

for_ :: (Generator c, Applicative f) => c -> (Elem c -> f b) -> f () #

Convenience function as found in Data.Foldable

        flip traverse_

asum :: (Generator c, Alternative f, f a ~ Elem c) => c -> f a #

The sum of a collection of actions, generalizing `concat`

       reduceWith getAlt

# Logical Reduction

and :: (Generator c, Elem c ~ Bool) => c -> Bool #

Efficiently `reduce` a `Generator` that contains values of type `Bool`

        reduceWith getAll

or :: (Generator c, Elem c ~ Bool) => c -> Bool #

Efficiently `reduce` a `Generator` that contains values of type `Bool`

        reduceWith getAny

any :: Generator c => (Elem c -> Bool) -> c -> Bool #

Efficiently `mapReduce` any `Generator` checking to see if any of its values match the supplied predicate

        mapReduceWith getAny

all :: Generator c => (Elem c -> Bool) -> c -> Bool #

Efficiently `mapReduce` any `Generator` checking to see if all of its values match the supplied predicate

        mapReduceWith getAll

# Monoidal Reduction

foldMap :: (Monoid m, Generator c) => (Elem c -> m) -> c -> m #

Efficiently `mapReduce` a `Generator` using the `WrappedMonoid` monoid. A specialized version of its namesake from Data.Foldable

        mapReduceWith unwrapMonoid

fold :: (Monoid m, Generator c, Elem c ~ m) => c -> m #

Efficiently `reduce` a `Generator` using the `WrappedMonoid` monoid. A specialized version of its namesake from Data.Foldable

        reduceWith unwrapMonoid

toList :: Generator c => c -> [Elem c] #

Convert any `Generator` to a list of its contents. Specialization of `reduce`

# List-Like Reduction

concatMap :: Generator c => (Elem c -> [b]) -> c -> [b] #

Type specialization of "foldMap" above

elem :: (Generator c, Eq (Elem c)) => Elem c -> c -> Bool #

Check to see if `any` member of the `Generator` matches the supplied value

filter :: (Generator c, Reducer (Elem c) m, Monoid m) => (Elem c -> Bool) -> c -> m #

Efficiently `mapReduce` a subset of the elements in a `Generator`

filterWith :: (Generator c, Reducer (Elem c) m, Monoid m) => (m -> n) -> (Elem c -> Bool) -> c -> n #

Allows idiomatic specialization of filter by proving a function that will be used to transform the output

sum :: (Generator c, Num (Elem c)) => c -> Elem c #

Efficiently sum over the members of any `Generator`

        reduceWith getSum

product :: (Generator c, Num (Elem c)) => c -> Elem c #

Efficiently take the product of every member of a `Generator`

        reduceWith getProduct

notElem :: (Generator c, Eq (Elem c)) => Elem c -> c -> Bool #

Check to make sure that the supplied value is not a member of the `Generator`