Data.Generator

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 | portable
Safe Haskell | Trustworthy
Language | Haskell98

Data.Generator

Contents

- Generators
- Generator Transformers
- Combinators

Description

A `Generator` `c` is a possibly-specialized container, which contains values of type `Elem` `c`, and which knows how to efficiently apply a `Reducer` to extract an answer.

Since a `Generator` is not polymorphic in its contents, it is more specialized than Data.Foldable.Foldable, and a `Reducer` may supply efficient left-to-right and right-to-left reduction strategies that a `Generator` may avail itself of.

Synopsis

- class Generator c where
  - type Elem c
  - mapReduce :: (Reducer e m, Monoid m) => (Elem c -> e) -> c -> m
  - mapTo :: (Reducer e m, Monoid m) => (Elem c -> e) -> m -> c -> m
  - mapFrom :: (Reducer e m, Monoid m) => (Elem c -> e) -> c -> m -> m
- newtype Keys c = Keys {
  - getKeys :: c
  }
- newtype Values c = Values {
  - getValues :: c
  }
- newtype Char8 c = Char8 {
  - getChar8 :: c
  }
- reduce :: (Generator c, Reducer (Elem c) m, Monoid m) => c -> m
- mapReduceWith :: (Generator c, Reducer e m, Monoid m) => (m -> n) -> (Elem c -> e) -> c -> n
- reduceWith :: (Generator c, Reducer (Elem c) m, Monoid m) => (m -> n) -> c -> n

# Generators

class Generator c where

minimal definition `mapReduce` or `mapTo`

Minimal complete definition

Nothing

Associated Types

type Elem c

Methods

mapReduce :: (Reducer e m, Monoid m) => (Elem c -> e) -> c -> m

mapTo :: (Reducer e m, Monoid m) => (Elem c -> e) -> m -> c -> m

mapFrom :: (Reducer e m, Monoid m) => (Elem c -> e) -> c -> m -> m

Instances

Generator ByteString |
Generator ByteString |
Generator IntSet |
Generator Text |
Generator [c] |
Generator (IntMap v) |
Generator (Set a) |
Generator (Seq c) |
Generator (NonEmpty c) |
Generator (HashSet a) |
Generator (Char8 ByteString) |
Generator (Char8 ByteString) |
Ix i => Generator (Values (Array i e)) |
Generator (Values (IntMap v)) |
Generator (Values (Map k v)) |
Ix i => Generator (Keys (Array i e)) |
Generator (Keys (IntMap v)) |
Generator (Keys (Map k v)) |
Ix i => Generator (Array i e) |
Generator (Map k v) |
Measured v e => Generator (FingerTree v e) |
Generator (HashMap k v) |

# Generator Transformers

newtype Keys c

a `Generator` transformer that asks only for the keys of an indexed container

Constructors

Keys |
Fields getKeys :: c

Instances

Ix i => Generator (Keys (Array i e)) |
Generator (Keys (IntMap v)) |
Generator (Keys (Map k v)) |
type Elem (Keys (Array i e)) = i |
type Elem (Keys (IntMap v)) = Int |
type Elem (Keys (Map k v)) = k |

newtype Values c

a `Generator` transformer that asks only for the values contained in an indexed container

Constructors

Values |
Fields getValues :: c

Instances

Ix i => Generator (Values (Array i e)) |
Generator (Values (IntMap v)) |
Generator (Values (Map k v)) |
type Elem (Values (Array i e)) = e |
type Elem (Values (IntMap v)) = v |
type Elem (Values (Map k v)) = v |

newtype Char8 c

a `Generator` transformer that treats `Word8` as `Char` This lets you use a `ByteString` as a `Char` source without going through a `Monoid` transformer like `UTF8`

Constructors

Char8 |
Fields getChar8 :: c

Instances

Generator (Char8 ByteString) |
Generator (Char8 ByteString) |
type Elem (Char8 ByteString) = Char |
type Elem (Char8 ByteString) = Char |

# Combinators

reduce :: (Generator c, Reducer (Elem c) m, Monoid m) => c -> m

Apply a `Reducer` directly to the elements of a `Generator`

mapReduceWith :: (Generator c, Reducer e m, Monoid m) => (m -> n) -> (Elem c -> e) -> c -> n

reduceWith :: (Generator c, Reducer (Elem c) m, Monoid m) => (m -> n) -> c -> n