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

Copyright | (c) Edward Kmett 2009-2016
License | BSD-style
Maintainer | ekmett@gmail.com
Stability | experimental
Portability | portable
Safe Haskell | Safe-Inferred
Language | Haskell2010

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 Source #

minimal definition `mapReduce` or `mapTo`

Minimal complete definition

Nothing

Associated Types

type Elem c Source #

Methods

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

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

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

#### Instances

Instances details

Generator ByteString Source # |

Instance details

Defined in Data.Generator

Associated Types

type Elem ByteString |
Instance details Defined in Data.Generator type Elem ByteString = Word8

Methods

mapReduce :: (Reducer e m, Monoid m) => (Elem ByteString -> e) -> ByteString -> m Source #

mapTo :: (Reducer e m, Monoid m) => (Elem ByteString -> e) -> m -> ByteString -> m Source #

mapFrom :: (Reducer e m, Monoid m) => (Elem ByteString -> e) -> ByteString -> m -> m Source #

Generator ByteString Source # |

Instance details

Defined in Data.Generator

Associated Types

type Elem ByteString |
Instance details Defined in Data.Generator type Elem ByteString = Word8

Methods

mapReduce :: (Reducer e m, Monoid m) => (Elem ByteString -> e) -> ByteString -> m Source #

mapTo :: (Reducer e m, Monoid m) => (Elem ByteString -> e) -> m -> ByteString -> m Source #

mapFrom :: (Reducer e m, Monoid m) => (Elem ByteString -> e) -> ByteString -> m -> m Source #

Generator IntSet Source # |

Instance details

Defined in Data.Generator

Associated Types

type Elem IntSet |
Instance details Defined in Data.Generator type Elem IntSet = Int

Methods

mapReduce :: (Reducer e m, Monoid m) => (Elem IntSet -> e) -> IntSet -> m Source #

mapTo :: (Reducer e m, Monoid m) => (Elem IntSet -> e) -> m -> IntSet -> m Source #

mapFrom :: (Reducer e m, Monoid m) => (Elem IntSet -> e) -> IntSet -> m -> m Source #

Generator Text Source # |

Instance details

Defined in Data.Generator

Associated Types

type Elem Text |
Instance details Defined in Data.Generator type Elem Text = Char

Methods

mapReduce :: (Reducer e m, Monoid m) => (Elem Text -> e) -> Text -> m Source #

mapTo :: (Reducer e m, Monoid m) => (Elem Text -> e) -> m -> Text -> m Source #

mapFrom :: (Reducer e m, Monoid m) => (Elem Text -> e) -> Text -> m -> m Source #

Generator (IntMap v) Source # |

Instance details

Defined in Data.Generator

Associated Types

type Elem (IntMap v) |
Instance details Defined in Data.Generator type Elem (IntMap v) = (Int, v)

Methods

mapReduce :: (Reducer e m, Monoid m) => (Elem (IntMap v) -> e) -> IntMap v -> m Source #

mapTo :: (Reducer e m, Monoid m) => (Elem (IntMap v) -> e) -> m -> IntMap v -> m Source #

mapFrom :: (Reducer e m, Monoid m) => (Elem (IntMap v) -> e) -> IntMap v -> m -> m Source #

Generator (Seq c) Source # |

Instance details

Defined in Data.Generator

Associated Types

type Elem (Seq c) |
Instance details Defined in Data.Generator type Elem (Seq c) = c

Methods

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

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

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

Generator (Set a) Source # |

Instance details

Defined in Data.Generator

Associated Types

type Elem (Set a) |
Instance details Defined in Data.Generator type Elem (Set a) = a

Methods

mapReduce :: (Reducer e m, Monoid m) => (Elem (Set a) -> e) -> Set a -> m Source #

mapTo :: (Reducer e m, Monoid m) => (Elem (Set a) -> e) -> m -> Set a -> m Source #

mapFrom :: (Reducer e m, Monoid m) => (Elem (Set a) -> e) -> Set a -> m -> m Source #

Generator (NonEmpty c) Source # |

Instance details

Defined in Data.Generator

Associated Types

type Elem (NonEmpty c) |
Instance details Defined in Data.Generator type Elem (NonEmpty c) = c

Methods

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

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

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

Generator (Char8 ByteString) Source # |

Instance details

Defined in Data.Generator

Associated Types

type Elem (Char8 ByteString) |
Instance details Defined in Data.Generator type Elem (Char8 ByteString) = Char

Methods

mapReduce :: (Reducer e m, Monoid m) => (Elem (Char8 ByteString) -> e) -> Char8 ByteString -> m Source #

mapTo :: (Reducer e m, Monoid m) => (Elem (Char8 ByteString) -> e) -> m -> Char8 ByteString -> m Source #

mapFrom :: (Reducer e m, Monoid m) => (Elem (Char8 ByteString) -> e) -> Char8 ByteString -> m -> m Source #

Generator (Char8 ByteString) Source # |

Instance details

Defined in Data.Generator

Associated Types

type Elem (Char8 ByteString) |
Instance details Defined in Data.Generator type Elem (Char8 ByteString) = Char

Methods

mapReduce :: (Reducer e m, Monoid m) => (Elem (Char8 ByteString) -> e) -> Char8 ByteString -> m Source #

mapTo :: (Reducer e m, Monoid m) => (Elem (Char8 ByteString) -> e) -> m -> Char8 ByteString -> m Source #

mapFrom :: (Reducer e m, Monoid m) => (Elem (Char8 ByteString) -> e) -> Char8 ByteString -> m -> m Source #

Generator (Keys (IntMap v)) Source # |

Instance details

Defined in Data.Generator

Associated Types

type Elem (Keys (IntMap v)) |
Instance details Defined in Data.Generator type Elem (Keys (IntMap v)) = Int

Methods

mapReduce :: (Reducer e m, Monoid m) => (Elem (Keys (IntMap v)) -> e) -> Keys (IntMap v) -> m Source #

mapTo :: (Reducer e m, Monoid m) => (Elem (Keys (IntMap v)) -> e) -> m -> Keys (IntMap v) -> m Source #

mapFrom :: (Reducer e m, Monoid m) => (Elem (Keys (IntMap v)) -> e) -> Keys (IntMap v) -> m -> m Source #

Generator (Keys (Map k v)) Source # |

Instance details

Defined in Data.Generator

Associated Types

type Elem (Keys (Map k v)) |
Instance details Defined in Data.Generator type Elem (Keys (Map k v)) = k

Methods

mapReduce :: (Reducer e m, Monoid m) => (Elem (Keys (Map k v)) -> e) -> Keys (Map k v) -> m Source #

mapTo :: (Reducer e m, Monoid m) => (Elem (Keys (Map k v)) -> e) -> m -> Keys (Map k v) -> m Source #

mapFrom :: (Reducer e m, Monoid m) => (Elem (Keys (Map k v)) -> e) -> Keys (Map k v) -> m -> m Source #

Ix i => Generator (Keys (Array i e)) Source # |

Instance details

Defined in Data.Generator

Associated Types

type Elem (Keys (Array i e)) |
Instance details Defined in Data.Generator type Elem (Keys (Array i e)) = i

Methods

mapReduce :: (Reducer e0 m, Monoid m) => (Elem (Keys (Array i e)) -> e0) -> Keys (Array i e) -> m Source #

mapTo :: (Reducer e0 m, Monoid m) => (Elem (Keys (Array i e)) -> e0) -> m -> Keys (Array i e) -> m Source #

mapFrom :: (Reducer e0 m, Monoid m) => (Elem (Keys (Array i e)) -> e0) -> Keys (Array i e) -> m -> m Source #

Generator (Values (IntMap v)) Source # |

Instance details

Defined in Data.Generator

Associated Types

type Elem (Values (IntMap v)) |
Instance details Defined in Data.Generator type Elem (Values (IntMap v)) = v

Methods

mapReduce :: (Reducer e m, Monoid m) => (Elem (Values (IntMap v)) -> e) -> Values (IntMap v) -> m Source #

mapTo :: (Reducer e m, Monoid m) => (Elem (Values (IntMap v)) -> e) -> m -> Values (IntMap v) -> m Source #

mapFrom :: (Reducer e m, Monoid m) => (Elem (Values (IntMap v)) -> e) -> Values (IntMap v) -> m -> m Source #

Generator (Values (Map k v)) Source # |

Instance details

Defined in Data.Generator

Associated Types

type Elem (Values (Map k v)) |
Instance details Defined in Data.Generator type Elem (Values (Map k v)) = v

Methods

mapReduce :: (Reducer e m, Monoid m) => (Elem (Values (Map k v)) -> e) -> Values (Map k v) -> m Source #

mapTo :: (Reducer e m, Monoid m) => (Elem (Values (Map k v)) -> e) -> m -> Values (Map k v) -> m Source #

mapFrom :: (Reducer e m, Monoid m) => (Elem (Values (Map k v)) -> e) -> Values (Map k v) -> m -> m Source #

Generator (Values (Array i e)) Source # |

Instance details

Defined in Data.Generator

Associated Types

type Elem (Values (Array i e)) |
Instance details Defined in Data.Generator type Elem (Values (Array i e)) = e

Methods

mapReduce :: (Reducer e0 m, Monoid m) => (Elem (Values (Array i e)) -> e0) -> Values (Array i e) -> m Source #

mapTo :: (Reducer e0 m, Monoid m) => (Elem (Values (Array i e)) -> e0) -> m -> Values (Array i e) -> m Source #

mapFrom :: (Reducer e0 m, Monoid m) => (Elem (Values (Array i e)) -> e0) -> Values (Array i e) -> m -> m Source #

Generator (HashSet a) Source # |

Instance details

Defined in Data.Generator

Associated Types

type Elem (HashSet a) |
Instance details Defined in Data.Generator type Elem (HashSet a) = a

Methods

mapReduce :: (Reducer e m, Monoid m) => (Elem (HashSet a) -> e) -> HashSet a -> m Source #

mapTo :: (Reducer e m, Monoid m) => (Elem (HashSet a) -> e) -> m -> HashSet a -> m Source #

mapFrom :: (Reducer e m, Monoid m) => (Elem (HashSet a) -> e) -> HashSet a -> m -> m Source #

Generator [c] Source # |

Instance details

Defined in Data.Generator

Associated Types

type Elem [c] |
Instance details Defined in Data.Generator type Elem [c] = c

Methods

mapReduce :: (Reducer e m, Monoid m) => (Elem [c] -> e) -> [c] -> m Source #

mapTo :: (Reducer e m, Monoid m) => (Elem [c] -> e) -> m -> [c] -> m Source #

mapFrom :: (Reducer e m, Monoid m) => (Elem [c] -> e) -> [c] -> m -> m Source #

Generator (Map k v) Source # |

Instance details

Defined in Data.Generator

Associated Types

type Elem (Map k v) |
Instance details Defined in Data.Generator type Elem (Map k v) = (k, v)

Methods

mapReduce :: (Reducer e m, Monoid m) => (Elem (Map k v) -> e) -> Map k v -> m Source #

mapTo :: (Reducer e m, Monoid m) => (Elem (Map k v) -> e) -> m -> Map k v -> m Source #

mapFrom :: (Reducer e m, Monoid m) => (Elem (Map k v) -> e) -> Map k v -> m -> m Source #

Generator (FingerTree v e) Source # |

Instance details

Defined in Data.Generator

Associated Types

type Elem (FingerTree v e) |
Instance details Defined in Data.Generator type Elem (FingerTree v e) = e

Methods

mapReduce :: (Reducer e0 m, Monoid m) => (Elem (FingerTree v e) -> e0) -> FingerTree v e -> m Source #

mapTo :: (Reducer e0 m, Monoid m) => (Elem (FingerTree v e) -> e0) -> m -> FingerTree v e -> m Source #

mapFrom :: (Reducer e0 m, Monoid m) => (Elem (FingerTree v e) -> e0) -> FingerTree v e -> m -> m Source #

Ix i => Generator (Array i e) Source # |

Instance details

Defined in Data.Generator

Associated Types

type Elem (Array i e) |
Instance details Defined in Data.Generator type Elem (Array i e) = (i, e)

Methods

mapReduce :: (Reducer e0 m, Monoid m) => (Elem (Array i e) -> e0) -> Array i e -> m Source #

mapTo :: (Reducer e0 m, Monoid m) => (Elem (Array i e) -> e0) -> m -> Array i e -> m Source #

mapFrom :: (Reducer e0 m, Monoid m) => (Elem (Array i e) -> e0) -> Array i e -> m -> m Source #

Generator (HashMap k v) Source # |

Instance details

Defined in Data.Generator

Associated Types

type Elem (HashMap k v) |
Instance details Defined in Data.Generator type Elem (HashMap k v) = (k, v)

Methods

mapReduce :: (Reducer e m, Monoid m) => (Elem (HashMap k v) -> e) -> HashMap k v -> m Source #

mapTo :: (Reducer e m, Monoid m) => (Elem (HashMap k v) -> e) -> m -> HashMap k v -> m Source #

mapFrom :: (Reducer e m, Monoid m) => (Elem (HashMap k v) -> e) -> HashMap k v -> m -> m Source #

# Generator Transformers

newtype Keys c Source #

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

Constructors

Keys |

Fields

- getKeys :: c

#### Instances

Instances details

Generator (Keys (IntMap v)) Source # |

Instance details

Defined in Data.Generator

Associated Types

type Elem (Keys (IntMap v)) |
Instance details Defined in Data.Generator type Elem (Keys (IntMap v)) = Int

Methods

mapReduce :: (Reducer e m, Monoid m) => (Elem (Keys (IntMap v)) -> e) -> Keys (IntMap v) -> m Source #

mapTo :: (Reducer e m, Monoid m) => (Elem (Keys (IntMap v)) -> e) -> m -> Keys (IntMap v) -> m Source #

mapFrom :: (Reducer e m, Monoid m) => (Elem (Keys (IntMap v)) -> e) -> Keys (IntMap v) -> m -> m Source #

Generator (Keys (Map k v)) Source # |

Instance details

Defined in Data.Generator

Associated Types

type Elem (Keys (Map k v)) |
Instance details Defined in Data.Generator type Elem (Keys (Map k v)) = k

Methods

mapReduce :: (Reducer e m, Monoid m) => (Elem (Keys (Map k v)) -> e) -> Keys (Map k v) -> m Source #

mapTo :: (Reducer e m, Monoid m) => (Elem (Keys (Map k v)) -> e) -> m -> Keys (Map k v) -> m Source #

mapFrom :: (Reducer e m, Monoid m) => (Elem (Keys (Map k v)) -> e) -> Keys (Map k v) -> m -> m Source #

Ix i => Generator (Keys (Array i e)) Source # |

Instance details

Defined in Data.Generator

Associated Types

type Elem (Keys (Array i e)) |
Instance details Defined in Data.Generator type Elem (Keys (Array i e)) = i

Methods

mapReduce :: (Reducer e0 m, Monoid m) => (Elem (Keys (Array i e)) -> e0) -> Keys (Array i e) -> m Source #

mapTo :: (Reducer e0 m, Monoid m) => (Elem (Keys (Array i e)) -> e0) -> m -> Keys (Array i e) -> m Source #

mapFrom :: (Reducer e0 m, Monoid m) => (Elem (Keys (Array i e)) -> e0) -> Keys (Array i e) -> m -> m Source #

type Elem (Keys (IntMap v)) Source # |
Instance details Defined in Data.Generator type Elem (Keys (IntMap v)) = Int
type Elem (Keys (Map k v)) Source # |
Instance details Defined in Data.Generator type Elem (Keys (Map k v)) = k
type Elem (Keys (Array i e)) Source # |
Instance details Defined in Data.Generator type Elem (Keys (Array i e)) = i

newtype Values c Source #

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

Constructors

Values |

Fields

- getValues :: c

#### Instances

Instances details

Generator (Values (IntMap v)) Source # |

Instance details

Defined in Data.Generator

Associated Types

type Elem (Values (IntMap v)) |
Instance details Defined in Data.Generator type Elem (Values (IntMap v)) = v

Methods

mapReduce :: (Reducer e m, Monoid m) => (Elem (Values (IntMap v)) -> e) -> Values (IntMap v) -> m Source #

mapTo :: (Reducer e m, Monoid m) => (Elem (Values (IntMap v)) -> e) -> m -> Values (IntMap v) -> m Source #

mapFrom :: (Reducer e m, Monoid m) => (Elem (Values (IntMap v)) -> e) -> Values (IntMap v) -> m -> m Source #

Generator (Values (Map k v)) Source # |

Instance details

Defined in Data.Generator

Associated Types

type Elem (Values (Map k v)) |
Instance details Defined in Data.Generator type Elem (Values (Map k v)) = v

Methods

mapReduce :: (Reducer e m, Monoid m) => (Elem (Values (Map k v)) -> e) -> Values (Map k v) -> m Source #

mapTo :: (Reducer e m, Monoid m) => (Elem (Values (Map k v)) -> e) -> m -> Values (Map k v) -> m Source #

mapFrom :: (Reducer e m, Monoid m) => (Elem (Values (Map k v)) -> e) -> Values (Map k v) -> m -> m Source #

Generator (Values (Array i e)) Source # |

Instance details

Defined in Data.Generator

Associated Types

type Elem (Values (Array i e)) |
Instance details Defined in Data.Generator type Elem (Values (Array i e)) = e

Methods

mapReduce :: (Reducer e0 m, Monoid m) => (Elem (Values (Array i e)) -> e0) -> Values (Array i e) -> m Source #

mapTo :: (Reducer e0 m, Monoid m) => (Elem (Values (Array i e)) -> e0) -> m -> Values (Array i e) -> m Source #

mapFrom :: (Reducer e0 m, Monoid m) => (Elem (Values (Array i e)) -> e0) -> Values (Array i e) -> m -> m Source #

type Elem (Values (IntMap v)) Source # |
Instance details Defined in Data.Generator type Elem (Values (IntMap v)) = v
type Elem (Values (Map k v)) Source # |
Instance details Defined in Data.Generator type Elem (Values (Map k v)) = v
type Elem (Values (Array i e)) Source # |
Instance details Defined in Data.Generator type Elem (Values (Array i e)) = e

newtype Char8 c Source #

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

Instances details

Generator (Char8 ByteString) Source # |

Instance details

Defined in Data.Generator

Associated Types

type Elem (Char8 ByteString) |
Instance details Defined in Data.Generator type Elem (Char8 ByteString) = Char

Methods

mapReduce :: (Reducer e m, Monoid m) => (Elem (Char8 ByteString) -> e) -> Char8 ByteString -> m Source #

mapTo :: (Reducer e m, Monoid m) => (Elem (Char8 ByteString) -> e) -> m -> Char8 ByteString -> m Source #

mapFrom :: (Reducer e m, Monoid m) => (Elem (Char8 ByteString) -> e) -> Char8 ByteString -> m -> m Source #

Generator (Char8 ByteString) Source # |

Instance details

Defined in Data.Generator

Associated Types

type Elem (Char8 ByteString) |
Instance details Defined in Data.Generator type Elem (Char8 ByteString) = Char

Methods

mapReduce :: (Reducer e m, Monoid m) => (Elem (Char8 ByteString) -> e) -> Char8 ByteString -> m Source #

mapTo :: (Reducer e m, Monoid m) => (Elem (Char8 ByteString) -> e) -> m -> Char8 ByteString -> m Source #

mapFrom :: (Reducer e m, Monoid m) => (Elem (Char8 ByteString) -> e) -> Char8 ByteString -> m -> m Source #

type Elem (Char8 ByteString) Source # |
Instance details Defined in Data.Generator type Elem (Char8 ByteString) = Char
type Elem (Char8 ByteString) Source # |
Instance details Defined in Data.Generator type Elem (Char8 ByteString) = Char

# Combinators

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

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 Source #

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