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

Copyright(c) Edward Kmett 2009
LicenseBSD3
Maintainerekmett@gmail.com
Stabilityexperimental
Portabilitynon-portable (MPTCs)
Safe HaskellTrustworthy
LanguageHaskell98

Data.Semigroup.Reducer

Description

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

Synopsis

Documentation

class Semigroup m => Reducer c m where #

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

Minimal complete definition

unit

Methods

unit :: c -> m #

Convert a value into a Semigroup

snoc :: m -> c -> m #

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

cons :: c -> m -> m #

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

Instances

Reducer Bool All # 

Methods

unit :: Bool -> All #

snoc :: All -> Bool -> All #

cons :: Bool -> All -> All #

Reducer Bool Any # 

Methods

unit :: Bool -> Any #

snoc :: Any -> Bool -> Any #

cons :: Bool -> Any -> Any #

Reducer Int IntSet # 

Methods

unit :: Int -> IntSet #

snoc :: IntSet -> Int -> IntSet #

cons :: Int -> IntSet -> IntSet #

Reducer c () # 

Methods

unit :: c -> () #

snoc :: () -> c -> () #

cons :: c -> () -> () #

Reducer a Count # 

Methods

unit :: a -> Count #

snoc :: Count -> a -> Count #

cons :: a -> Count -> Count #

Monoid m => Reducer m (WrappedMonoid m) # 

Methods

unit :: m -> WrappedMonoid m #

snoc :: WrappedMonoid m -> m -> WrappedMonoid m #

cons :: m -> WrappedMonoid m -> WrappedMonoid m #

Ord a => Reducer a (Set a) # 

Methods

unit :: a -> Set a #

snoc :: Set a -> a -> Set a #

cons :: a -> Set a -> Set a #

Reducer a (Seq a) # 

Methods

unit :: a -> Seq a #

snoc :: Seq a -> a -> Seq a #

cons :: a -> Seq a -> Seq a #

Reducer a (Last a) # 

Methods

unit :: a -> Last a #

snoc :: Last a -> a -> Last a #

cons :: a -> Last a -> Last a #

Reducer a (First a) # 

Methods

unit :: a -> First a #

snoc :: First a -> a -> First a #

cons :: a -> First a -> First a #

Ord a => Reducer a (Max a) # 

Methods

unit :: a -> Max a #

snoc :: Max a -> a -> Max a #

cons :: a -> Max a -> Max a #

Ord a => Reducer a (Min a) # 

Methods

unit :: a -> Min a #

snoc :: Min a -> a -> Min a #

cons :: a -> Min a -> Min a #

Num a => Reducer a (Product a) # 

Methods

unit :: a -> Product a #

snoc :: Product a -> a -> Product a #

cons :: a -> Product a -> Product a #

Num a => Reducer a (Sum a) # 

Methods

unit :: a -> Sum a #

snoc :: Sum a -> a -> Sum a #

cons :: a -> Sum a -> Sum a #

Semigroup a => Reducer a (Dual a) # 

Methods

unit :: a -> Dual a #

snoc :: Dual a -> a -> Dual a #

cons :: a -> Dual a -> Dual a #

Reducer c [c] # 

Methods

unit :: c -> [c] #

snoc :: [c] -> c -> [c] #

cons :: c -> [c] -> [c] #

Semigroup m => Reducer m (Self m) # 

Methods

unit :: m -> Self m #

snoc :: Self m -> m -> Self m #

cons :: m -> Self m -> Self m #

HasUnion f => Reducer f (Union f) # 

Methods

unit :: f -> Union f #

snoc :: Union f -> f -> Union f #

cons :: f -> Union f -> Union f #

Measured v a => Reducer a (FingerTree v a) # 

Methods

unit :: a -> FingerTree v a #

snoc :: FingerTree v a -> a -> FingerTree v a #

cons :: a -> FingerTree v a -> FingerTree v a #

(Reducer c m, Reducer c n) => Reducer c (m, n) # 

Methods

unit :: c -> (m, n) #

snoc :: (m, n) -> c -> (m, n) #

cons :: c -> (m, n) -> (m, n) #

(Reducer c m, Reducer c n, Reducer c o) => Reducer c (m, n, o) # 

Methods

unit :: c -> (m, n, o) #

snoc :: (m, n, o) -> c -> (m, n, o) #

cons :: c -> (m, n, o) -> (m, n, o) #

(Reducer c m, Reducer c n, Reducer c o, Reducer c p) => Reducer c (m, n, o, p) # 

Methods

unit :: c -> (m, n, o, p) #

snoc :: (m, n, o, p) -> c -> (m, n, o, p) #

cons :: c -> (m, n, o, p) -> (m, n, o, p) #

Reducer (Maybe a) (Last a) # 

Methods

unit :: Maybe a -> Last a #

snoc :: Last a -> Maybe a -> Last a #

cons :: Maybe a -> Last a -> Last a #

Reducer (Maybe a) (First a) # 

Methods

unit :: Maybe a -> First a #

snoc :: First a -> Maybe a -> First a #

cons :: Maybe a -> First a -> First a #

Monad f => Reducer (f a) (Action f) # 

Methods

unit :: f a -> Action f #

snoc :: Action f -> f a -> Action f #

cons :: f a -> Action f -> Action f #

Apply f => Reducer (f a) (Trav f) # 

Methods

unit :: f a -> Trav f #

snoc :: Trav f -> f a -> Trav f #

cons :: f a -> Trav f -> Trav f #

Applicative f => Reducer (f a) (Traversal f) # 

Methods

unit :: f a -> Traversal f #

snoc :: Traversal f -> f a -> Traversal f #

cons :: f a -> Traversal f -> Traversal f #

(Monad f, Reducer c m) => Reducer (f c) (Mon f m) # 

Methods

unit :: f c -> Mon f m #

snoc :: Mon f m -> f c -> Mon f m #

cons :: f c -> Mon f m -> Mon f m #

MonadPlus f => Reducer (f a) (MonadSum f a) # 

Methods

unit :: f a -> MonadSum f a #

snoc :: MonadSum f a -> f a -> MonadSum f a #

cons :: f a -> MonadSum f a -> MonadSum f a #

(HasUnionWith f, Semigroup m, Monoid m) => Reducer (f m) (UnionWith f m) # 

Methods

unit :: f m -> UnionWith f m #

snoc :: UnionWith f m -> f m -> UnionWith f m #

cons :: f m -> UnionWith f m -> UnionWith f m #

(Apply f, Reducer c m) => Reducer (f c) (App f m) # 

Methods

unit :: f c -> App f m #

snoc :: App f m -> f c -> App f m #

cons :: f c -> App f m -> App f m #

(Applicative f, Reducer c m) => Reducer (f c) (Ap f m) # 

Methods

unit :: f c -> Ap f m #

snoc :: Ap f m -> f c -> Ap f m #

cons :: f c -> Ap f m -> Ap f m #

Alternative f => Reducer (f a) (Alternate f a) # 

Methods

unit :: f a -> Alternate f a #

snoc :: Alternate f a -> f a -> Alternate f a #

cons :: f a -> Alternate f a -> Alternate f a #

Alt f => Reducer (f a) (Alter f a) # 

Methods

unit :: f a -> Alter f a #

snoc :: Alter f a -> f a -> Alter f a #

cons :: f a -> Alter f a -> Alter f a #

Reducer c m => Reducer (WithReducer m c) m # 

Methods

unit :: WithReducer m c -> m #

snoc :: m -> WithReducer m c -> m #

cons :: WithReducer m c -> m -> m #

Reducer (a -> a) (Endo a) # 

Methods

unit :: (a -> a) -> Endo a #

snoc :: Endo a -> (a -> a) -> Endo a #

cons :: (a -> a) -> Endo a -> Endo a #

Reducer (Int, v) (IntMap v) # 

Methods

unit :: (Int, v) -> IntMap v #

snoc :: IntMap v -> (Int, v) -> IntMap v #

cons :: (Int, v) -> IntMap v -> IntMap v #

Ord k => Reducer (k, v) (Map k v) # 

Methods

unit :: (k, v) -> Map k v #

snoc :: Map k v -> (k, v) -> Map k v #

cons :: (k, v) -> Map k v -> Map k v #

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

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

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

Apply a Reducer to a Foldable mapping each element through unit

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

Apply a Reducer to a Foldable1 mapping each element through unit

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

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

newtype Count #

Constructors

Count 

Fields

Instances

Eq Count # 

Methods

(==) :: Count -> Count -> Bool #

(/=) :: Count -> Count -> Bool #

Data Count # 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Count -> c Count #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Count #

toConstr :: Count -> Constr #

dataTypeOf :: Count -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c Count) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Count) #

gmapT :: (forall b. Data b => b -> b) -> Count -> Count #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Count -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Count -> r #

gmapQ :: (forall d. Data d => d -> u) -> Count -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Count -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Count -> m Count #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Count -> m Count #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Count -> m Count #

Ord Count # 

Methods

compare :: Count -> Count -> Ordering #

(<) :: Count -> Count -> Bool #

(<=) :: Count -> Count -> Bool #

(>) :: Count -> Count -> Bool #

(>=) :: Count -> Count -> Bool #

max :: Count -> Count -> Count #

min :: Count -> Count -> Count #

Read Count # 
Show Count # 

Methods

showsPrec :: Int -> Count -> ShowS #

show :: Count -> String #

showList :: [Count] -> ShowS #

Semigroup Count # 

Methods

(<>) :: Count -> Count -> Count #

sconcat :: NonEmpty Count -> Count #

stimes :: Integral b => b -> Count -> Count #

Monoid Count # 

Methods

mempty :: Count #

mappend :: Count -> Count -> Count #

mconcat :: [Count] -> Count #

Hashable Count # 

Methods

hashWithSalt :: Int -> Count -> Int #

hash :: Count -> Int #

Reducer a Count # 

Methods

unit :: a -> Count #

snoc :: Count -> a -> Count #

cons :: a -> Count -> Count #