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

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 # |
Associated Types type Elem ByteString :: * # Methods mapReduce :: (Reducer e m, Monoid m) => (Elem ByteString -> e) -> ByteString -> m # mapTo :: (Reducer e m, Monoid m) => (Elem ByteString -> e) -> m -> ByteString -> m # mapFrom :: (Reducer e m, Monoid m) => (Elem ByteString -> e) -> ByteString -> m -> m #
Generator ByteString # |
Associated Types type Elem ByteString :: * # Methods mapReduce :: (Reducer e m, Monoid m) => (Elem ByteString -> e) -> ByteString -> m # mapTo :: (Reducer e m, Monoid m) => (Elem ByteString -> e) -> m -> ByteString -> m # mapFrom :: (Reducer e m, Monoid m) => (Elem ByteString -> e) -> ByteString -> m -> m #
Generator IntSet # |
Associated Types type Elem IntSet :: * # Methods mapReduce :: (Reducer e m, Monoid m) => (Elem IntSet -> e) -> IntSet -> m # mapTo :: (Reducer e m, Monoid m) => (Elem IntSet -> e) -> m -> IntSet -> m # mapFrom :: (Reducer e m, Monoid m) => (Elem IntSet -> e) -> IntSet -> m -> m #
Generator Text # |
Associated Types type Elem Text :: * # Methods mapReduce :: (Reducer e m, Monoid m) => (Elem Text -> e) -> Text -> m # mapTo :: (Reducer e m, Monoid m) => (Elem Text -> e) -> m -> Text -> m # mapFrom :: (Reducer e m, Monoid m) => (Elem Text -> e) -> Text -> m -> m #
Generator [c] # |
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 #
Generator (NonEmpty c) # |
Associated Types type Elem (NonEmpty c) :: * # Methods mapReduce :: (Reducer e m, Monoid m) => (Elem (NonEmpty c) -> e) -> NonEmpty c -> m # mapTo :: (Reducer e m, Monoid m) => (Elem (NonEmpty c) -> e) -> m -> NonEmpty c -> m # mapFrom :: (Reducer e m, Monoid m) => (Elem (NonEmpty c) -> e) -> NonEmpty c -> m -> m #
Generator (Seq c) # |
Associated Types type Elem (Seq c) :: * # Methods mapReduce :: (Reducer e m, Monoid m) => (Elem (Seq c) -> e) -> Seq c -> m # mapTo :: (Reducer e m, Monoid m) => (Elem (Seq c) -> e) -> m -> Seq c -> m # mapFrom :: (Reducer e m, Monoid m) => (Elem (Seq c) -> e) -> Seq c -> m -> m #
Generator (IntMap v) # |
Associated Types type Elem (IntMap v) :: * # Methods mapReduce :: (Reducer e m, Monoid m) => (Elem (IntMap v) -> e) -> IntMap v -> m # mapTo :: (Reducer e m, Monoid m) => (Elem (IntMap v) -> e) -> m -> IntMap v -> m # mapFrom :: (Reducer e m, Monoid m) => (Elem (IntMap v) -> e) -> IntMap v -> m -> m #
Generator (Set a) # |
Associated Types type Elem (Set a) :: * # Methods mapReduce :: (Reducer e m, Monoid m) => (Elem (Set a) -> e) -> Set a -> m # mapTo :: (Reducer e m, Monoid m) => (Elem (Set a) -> e) -> m -> Set a -> m # mapFrom :: (Reducer e m, Monoid m) => (Elem (Set a) -> e) -> Set a -> m -> m #
Generator (HashSet a) # |
Associated Types type Elem (HashSet a) :: * # Methods mapReduce :: (Reducer e m, Monoid m) => (Elem (HashSet a) -> e) -> HashSet a -> m # mapTo :: (Reducer e m, Monoid m) => (Elem (HashSet a) -> e) -> m -> HashSet a -> m # mapFrom :: (Reducer e m, Monoid m) => (Elem (HashSet a) -> e) -> HashSet a -> m -> m #
Generator (Char8 ByteString) # |
Associated Types type Elem (Char8 ByteString) :: * # Methods mapReduce :: (Reducer e m, Monoid m) => (Elem (Char8 ByteString) -> e) -> Char8 ByteString -> m # mapTo :: (Reducer e m, Monoid m) => (Elem (Char8 ByteString) -> e) -> m -> Char8 ByteString -> m # mapFrom :: (Reducer e m, Monoid m) => (Elem (Char8 ByteString) -> e) -> Char8 ByteString -> m -> m #
Generator (Char8 ByteString) # |
Associated Types type Elem (Char8 ByteString) :: * # Methods mapReduce :: (Reducer e m, Monoid m) => (Elem (Char8 ByteString) -> e) -> Char8 ByteString -> m # mapTo :: (Reducer e m, Monoid m) => (Elem (Char8 ByteString) -> e) -> m -> Char8 ByteString -> m # mapFrom :: (Reducer e m, Monoid m) => (Elem (Char8 ByteString) -> e) -> Char8 ByteString -> m -> m #
Ix i => Generator (Values (Array i e)) # |
Associated Types type Elem (Values (Array i e)) :: * # Methods mapReduce :: (Reducer e m, Monoid m) => (Elem (Values (Array i e)) -> e) -> Values (Array i e) -> m # mapTo :: (Reducer e m, Monoid m) => (Elem (Values (Array i e)) -> e) -> m -> Values (Array i e) -> m # mapFrom :: (Reducer e m, Monoid m) => (Elem (Values (Array i e)) -> e) -> Values (Array i e) -> m -> m #
Generator (Values (IntMap v)) # |
Associated Types type Elem (Values (IntMap v)) :: * # Methods mapReduce :: (Reducer e m, Monoid m) => (Elem (Values (IntMap v)) -> e) -> Values (IntMap v) -> m # mapTo :: (Reducer e m, Monoid m) => (Elem (Values (IntMap v)) -> e) -> m -> Values (IntMap v) -> m # mapFrom :: (Reducer e m, Monoid m) => (Elem (Values (IntMap v)) -> e) -> Values (IntMap v) -> m -> m #
Generator (Values (Map k v)) # |
Associated Types type Elem (Values (Map k v)) :: * # Methods mapReduce :: (Reducer e m, Monoid m) => (Elem (Values (Map k v)) -> e) -> Values (Map k v) -> m # mapTo :: (Reducer e m, Monoid m) => (Elem (Values (Map k v)) -> e) -> m -> Values (Map k v) -> m # mapFrom :: (Reducer e m, Monoid m) => (Elem (Values (Map k v)) -> e) -> Values (Map k v) -> m -> m #
Ix i => Generator (Keys (Array i e)) # |
Associated Types type Elem (Keys (Array i e)) :: * # Methods mapReduce :: (Reducer e m, Monoid m) => (Elem (Keys (Array i e)) -> e) -> Keys (Array i e) -> m # mapTo :: (Reducer e m, Monoid m) => (Elem (Keys (Array i e)) -> e) -> m -> Keys (Array i e) -> m # mapFrom :: (Reducer e m, Monoid m) => (Elem (Keys (Array i e)) -> e) -> Keys (Array i e) -> m -> m #
Generator (Keys (IntMap v)) # |
Associated Types type Elem (Keys (IntMap v)) :: * # Methods mapReduce :: (Reducer e m, Monoid m) => (Elem (Keys (IntMap v)) -> e) -> Keys (IntMap v) -> m # mapTo :: (Reducer e m, Monoid m) => (Elem (Keys (IntMap v)) -> e) -> m -> Keys (IntMap v) -> m # mapFrom :: (Reducer e m, Monoid m) => (Elem (Keys (IntMap v)) -> e) -> Keys (IntMap v) -> m -> m #
Generator (Keys (Map k v)) # |
Associated Types type Elem (Keys (Map k v)) :: * # Methods mapReduce :: (Reducer e m, Monoid m) => (Elem (Keys (Map k v)) -> e) -> Keys (Map k v) -> m # mapTo :: (Reducer e m, Monoid m) => (Elem (Keys (Map k v)) -> e) -> m -> Keys (Map k v) -> m # mapFrom :: (Reducer e m, Monoid m) => (Elem (Keys (Map k v)) -> e) -> Keys (Map k v) -> m -> m #
Ix i => Generator (Array i e) # |
Associated Types type Elem (Array i e) :: * # Methods mapReduce :: (Reducer e m, Monoid m) => (Elem (Array i e) -> e) -> Array i e -> m # mapTo :: (Reducer e m, Monoid m) => (Elem (Array i e) -> e) -> m -> Array i e -> m # mapFrom :: (Reducer e m, Monoid m) => (Elem (Array i e) -> e) -> Array i e -> m -> m #
Generator (Map k v) # |
Associated Types type Elem (Map k v) :: * # Methods mapReduce :: (Reducer e m, Monoid m) => (Elem (Map k v) -> e) -> Map k v -> m # mapTo :: (Reducer e m, Monoid m) => (Elem (Map k v) -> e) -> m -> Map k v -> m # mapFrom :: (Reducer e m, Monoid m) => (Elem (Map k v) -> e) -> Map k v -> m -> m #
Measured v e => Generator (FingerTree v e) # |
Associated Types type Elem (FingerTree v e) :: * # Methods mapReduce :: (Reducer e m, Monoid m) => (Elem (FingerTree v e) -> e) -> FingerTree v e -> m # mapTo :: (Reducer e m, Monoid m) => (Elem (FingerTree v e) -> e) -> m -> FingerTree v e -> m # mapFrom :: (Reducer e m, Monoid m) => (Elem (FingerTree v e) -> e) -> FingerTree v e -> m -> m #
Generator (HashMap k v) # |
Associated Types type Elem (HashMap k v) :: * # Methods mapReduce :: (Reducer e m, Monoid m) => (Elem (HashMap k v) -> e) -> HashMap k v -> m # mapTo :: (Reducer e m, Monoid m) => (Elem (HashMap k v) -> e) -> m -> HashMap k v -> m # mapFrom :: (Reducer e m, Monoid m) => (Elem (HashMap k v) -> e) -> HashMap k v -> m -> m #

# 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)) # |
Associated Types type Elem (Keys (Array i e)) :: * # Methods mapReduce :: (Reducer e m, Monoid m) => (Elem (Keys (Array i e)) -> e) -> Keys (Array i e) -> m # mapTo :: (Reducer e m, Monoid m) => (Elem (Keys (Array i e)) -> e) -> m -> Keys (Array i e) -> m # mapFrom :: (Reducer e m, Monoid m) => (Elem (Keys (Array i e)) -> e) -> Keys (Array i e) -> m -> m #
Generator (Keys (IntMap v)) # |
Associated Types type Elem (Keys (IntMap v)) :: * # Methods mapReduce :: (Reducer e m, Monoid m) => (Elem (Keys (IntMap v)) -> e) -> Keys (IntMap v) -> m # mapTo :: (Reducer e m, Monoid m) => (Elem (Keys (IntMap v)) -> e) -> m -> Keys (IntMap v) -> m # mapFrom :: (Reducer e m, Monoid m) => (Elem (Keys (IntMap v)) -> e) -> Keys (IntMap v) -> m -> m #
Generator (Keys (Map k v)) # |
Associated Types type Elem (Keys (Map k v)) :: * # Methods mapReduce :: (Reducer e m, Monoid m) => (Elem (Keys (Map k v)) -> e) -> Keys (Map k v) -> m # mapTo :: (Reducer e m, Monoid m) => (Elem (Keys (Map k v)) -> e) -> m -> Keys (Map k v) -> m # mapFrom :: (Reducer e m, Monoid m) => (Elem (Keys (Map k v)) -> e) -> Keys (Map k v) -> m -> m #
type Elem (Keys (Array i e)) # |
type Elem (Keys (Array i e)) = i
type Elem (Keys (IntMap v)) # |
type Elem (Keys (IntMap v)) = Int
type Elem (Keys (Map k v)) # |
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)) # |
Associated Types type Elem (Values (Array i e)) :: * # Methods mapReduce :: (Reducer e m, Monoid m) => (Elem (Values (Array i e)) -> e) -> Values (Array i e) -> m # mapTo :: (Reducer e m, Monoid m) => (Elem (Values (Array i e)) -> e) -> m -> Values (Array i e) -> m # mapFrom :: (Reducer e m, Monoid m) => (Elem (Values (Array i e)) -> e) -> Values (Array i e) -> m -> m #
Generator (Values (IntMap v)) # |
Associated Types type Elem (Values (IntMap v)) :: * # Methods mapReduce :: (Reducer e m, Monoid m) => (Elem (Values (IntMap v)) -> e) -> Values (IntMap v) -> m # mapTo :: (Reducer e m, Monoid m) => (Elem (Values (IntMap v)) -> e) -> m -> Values (IntMap v) -> m # mapFrom :: (Reducer e m, Monoid m) => (Elem (Values (IntMap v)) -> e) -> Values (IntMap v) -> m -> m #
Generator (Values (Map k v)) # |
Associated Types type Elem (Values (Map k v)) :: * # Methods mapReduce :: (Reducer e m, Monoid m) => (Elem (Values (Map k v)) -> e) -> Values (Map k v) -> m # mapTo :: (Reducer e m, Monoid m) => (Elem (Values (Map k v)) -> e) -> m -> Values (Map k v) -> m # mapFrom :: (Reducer e m, Monoid m) => (Elem (Values (Map k v)) -> e) -> Values (Map k v) -> m -> m #
type Elem (Values (Array i e)) # |
type Elem (Values (Array i e)) = e
type Elem (Values (IntMap v)) # |
type Elem (Values (IntMap v)) = v
type Elem (Values (Map k 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) # |
Associated Types type Elem (Char8 ByteString) :: * # Methods mapReduce :: (Reducer e m, Monoid m) => (Elem (Char8 ByteString) -> e) -> Char8 ByteString -> m # mapTo :: (Reducer e m, Monoid m) => (Elem (Char8 ByteString) -> e) -> m -> Char8 ByteString -> m # mapFrom :: (Reducer e m, Monoid m) => (Elem (Char8 ByteString) -> e) -> Char8 ByteString -> m -> m #
Generator (Char8 ByteString) # |
Associated Types type Elem (Char8 ByteString) :: * # Methods mapReduce :: (Reducer e m, Monoid m) => (Elem (Char8 ByteString) -> e) -> Char8 ByteString -> m # mapTo :: (Reducer e m, Monoid m) => (Elem (Char8 ByteString) -> e) -> m -> Char8 ByteString -> m # mapFrom :: (Reducer e m, Monoid m) => (Elem (Char8 ByteString) -> e) -> Char8 ByteString -> m -> m #
type Elem (Char8 ByteString) # |
type Elem (Char8 ByteString) = Char
type Elem (Char8 ByteString) # |
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 #