endo-0.3.0.0: Endomorphism utilities.

Copyright(c) 2015-2016 Peter Trško
LicenseBSD3
Maintainerpeter.trsko@gmail.com
Stabilityexperimental
PortabilityCPP, DeriveFoldable, DeriveFunctor, DeriveDataTypeable, DeriveGeneric, DeriveTraversable, FlexibleInstances, NoImplicitPrelude, TypeFamilies
Safe HaskellNone
LanguageHaskell2010

Data.Monoid.Endo.Apply

Contents

Description

ApplyEndo provides easier endomorphism evaluation in cases when there is an "obvious" default value.

Synopsis

ApplyEndo

newtype ApplyEndo t f a Source #

There are cases when it is "obvious" what is the default value, which should be modified by the endomorphism. This type is a result of such endomorphism application and it uses phantom type t as distinguishing property, which decides what is the correct "default value".

Constructors

ApplyEndo 

Fields

Instances

Monad f => Monad (ApplyEndo t f) Source # 

Methods

(>>=) :: ApplyEndo t f a -> (a -> ApplyEndo t f b) -> ApplyEndo t f b #

(>>) :: ApplyEndo t f a -> ApplyEndo t f b -> ApplyEndo t f b #

return :: a -> ApplyEndo t f a #

fail :: String -> ApplyEndo t f a #

Functor f => Functor (ApplyEndo t f) Source # 

Methods

fmap :: (a -> b) -> ApplyEndo t f a -> ApplyEndo t f b #

(<$) :: a -> ApplyEndo t f b -> ApplyEndo t f a #

Applicative f => Applicative (ApplyEndo t f) Source # 

Methods

pure :: a -> ApplyEndo t f a #

(<*>) :: ApplyEndo t f (a -> b) -> ApplyEndo t f a -> ApplyEndo t f b #

(*>) :: ApplyEndo t f a -> ApplyEndo t f b -> ApplyEndo t f b #

(<*) :: ApplyEndo t f a -> ApplyEndo t f b -> ApplyEndo t f a #

Foldable f => Foldable (ApplyEndo t f) Source # 

Methods

fold :: Monoid m => ApplyEndo t f m -> m #

foldMap :: Monoid m => (a -> m) -> ApplyEndo t f a -> m #

foldr :: (a -> b -> b) -> b -> ApplyEndo t f a -> b #

foldr' :: (a -> b -> b) -> b -> ApplyEndo t f a -> b #

foldl :: (b -> a -> b) -> b -> ApplyEndo t f a -> b #

foldl' :: (b -> a -> b) -> b -> ApplyEndo t f a -> b #

foldr1 :: (a -> a -> a) -> ApplyEndo t f a -> a #

foldl1 :: (a -> a -> a) -> ApplyEndo t f a -> a #

toList :: ApplyEndo t f a -> [a] #

null :: ApplyEndo t f a -> Bool #

length :: ApplyEndo t f a -> Int #

elem :: Eq a => a -> ApplyEndo t f a -> Bool #

maximum :: Ord a => ApplyEndo t f a -> a #

minimum :: Ord a => ApplyEndo t f a -> a #

sum :: Num a => ApplyEndo t f a -> a #

product :: Num a => ApplyEndo t f a -> a #

Traversable f => Traversable (ApplyEndo t f) Source # 

Methods

traverse :: Applicative f => (a -> f b) -> ApplyEndo t f a -> f (ApplyEndo t f b) #

sequenceA :: Applicative f => ApplyEndo t f (f a) -> f (ApplyEndo t f a) #

mapM :: Monad m => (a -> m b) -> ApplyEndo t f a -> m (ApplyEndo t f b) #

sequence :: Monad m => ApplyEndo t f (m a) -> m (ApplyEndo t f a) #

Generic1 (ApplyEndo t f) Source # 

Associated Types

type Rep1 (ApplyEndo t f :: * -> *) :: * -> * #

Methods

from1 :: ApplyEndo t f a -> Rep1 (ApplyEndo t f) a #

to1 :: Rep1 (ApplyEndo t f) a -> ApplyEndo t f a #

Eq1 f => Eq1 (ApplyEndo t f) Source # 

Methods

liftEq :: (a -> b -> Bool) -> ApplyEndo t f a -> ApplyEndo t f b -> Bool #

Ord1 f => Ord1 (ApplyEndo t f) Source # 

Methods

liftCompare :: (a -> b -> Ordering) -> ApplyEndo t f a -> ApplyEndo t f b -> Ordering #

Read1 f => Read1 (ApplyEndo t f) Source # 

Methods

liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (ApplyEndo t f a) #

liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [ApplyEndo t f a] #

Show1 f => Show1 (ApplyEndo t f) Source # 

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> ApplyEndo t f a -> ShowS #

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [ApplyEndo t f a] -> ShowS #

(Data (f a), Typeable * a, Typeable * t, Typeable (* -> *) f) => Data (ApplyEndo t f a) Source # 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ApplyEndo t f a -> c (ApplyEndo t f a) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (ApplyEndo t f a) #

toConstr :: ApplyEndo t f a -> Constr #

dataTypeOf :: ApplyEndo t f a -> DataType #

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

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

gmapT :: (forall b. Data b => b -> b) -> ApplyEndo t f a -> ApplyEndo t f a #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ApplyEndo t f a -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ApplyEndo t f a -> r #

gmapQ :: (forall d. Data d => d -> u) -> ApplyEndo t f a -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> ApplyEndo t f a -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> ApplyEndo t f a -> m (ApplyEndo t f a) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ApplyEndo t f a -> m (ApplyEndo t f a) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ApplyEndo t f a -> m (ApplyEndo t f a) #

Generic (ApplyEndo t f a) Source # 

Associated Types

type Rep (ApplyEndo t f a) :: * -> * #

Methods

from :: ApplyEndo t f a -> Rep (ApplyEndo t f a) x #

to :: Rep (ApplyEndo t f a) x -> ApplyEndo t f a #

MonadState s m => FromEndo (ApplyEndo Modify' m s) Source #

Evaluates ApplyEndo in terms of state operation:

fromEndo (Endo f) = ApplyEndo . state $ \s ->
    let s' = f s in s' `seq` (s', s')
MonadState s m => FromEndo (ApplyEndo Modify m s) Source #

Evaluates ApplyEndo in terms of state operation:

fromEndo e = ApplyEndo . state $ \s ->
    let s' = appEndo e s in (s', s')
MonadReader r m => FromEndo (ApplyEndo Reader m r) Source #

Evaluates ApplyEndo in terms of asks operation:

fromEndo = ApplyEndo . asks . appEndo
(Applicative f, Default a) => FromEndo (ApplyEndo Def f a) Source # 
(Applicative f, Monoid a) => FromEndo (ApplyEndo Mempty f a) Source # 
type Rep1 (ApplyEndo t f) Source # 
type Rep1 (ApplyEndo t f) = D1 (MetaData "ApplyEndo" "Data.Monoid.Endo.Apply" "endo-0.3.0.0-FDoQmRwl62o5XNvfgqOehr" True) (C1 (MetaCons "ApplyEndo" PrefixI True) (S1 (MetaSel (Just Symbol "applyEndo") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec1 f)))
type Rep (ApplyEndo t f a) Source # 
type Rep (ApplyEndo t f a) = D1 (MetaData "ApplyEndo" "Data.Monoid.Endo.Apply" "endo-0.3.0.0-FDoQmRwl62o5XNvfgqOehr" True) (C1 (MetaCons "ApplyEndo" PrefixI True) (S1 (MetaSel (Just Symbol "applyEndo") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (f a))))
type EndoOperatedOn (ApplyEndo Modify' m s) Source # 
type EndoOperatedOn (ApplyEndo Modify m s) Source # 
type EndoOperatedOn (ApplyEndo Reader m r) Source # 
type EndoOperatedOn (ApplyEndo Def f a) Source # 
type EndoOperatedOn (ApplyEndo Mempty f a) Source # 

apply :: Applicative f => a -> Endo a -> ApplyEndo t f a Source #

Apply endomorphism using provided "default" value.

applyF :: Functor f => a -> f (Endo a) -> ApplyEndo t f a Source #

Similar as apply, but expects Endo to be wrapped by a Functor.

ApplyEndo Mempty

data Mempty Source #

Type tag identifying usage of mempty from Monoid.

Instances

Generic Mempty Source # 

Associated Types

type Rep Mempty :: * -> * #

Methods

from :: Mempty -> Rep Mempty x #

to :: Rep Mempty x -> Mempty #

(Applicative f, Monoid a) => FromEndo (ApplyEndo Mempty f a) Source # 
type Rep Mempty Source # 
type Rep Mempty = D1 (MetaData "Mempty" "Data.Monoid.Endo.Apply" "endo-0.3.0.0-FDoQmRwl62o5XNvfgqOehr" False) V1
type EndoOperatedOn (ApplyEndo Mempty f a) Source # 

applyMempty :: Monoid a => ApplyEndo Mempty f a -> f a Source #

Constrained version of applyEndo. Usage example:

applyMempty . fromEndo :: (Applicative f, Monoid a) => Endo a -> f a

applyMempty_ :: Monoid a => ApplyEndo Mempty Identity a -> a Source #

Same as applyMempty, but Applicative functor is specialized to Identity functor and evaluated.

Examples:

>>> fromEndoWith applyMempty_ $ foldEndo (+1) [(*10), (+42)] :: Int
421
>>> fromEndoWith applyMempty_ $ dualFoldEndo (+1) [(*10), (+42)] :: Int
52

joinApplyMempty :: (Monad m, Monoid a) => m (ApplyEndo Mempty m a) -> m a Source #

Evaluates ApplyEndo in a Monad by joining it with the monad it contains. It can be also viewed as a variant of applyMempty defined as:

joinApplyMempty = (>>= applyMempty)

ApplyEndo Def

Apply endomorphism to a default value def from Default. See also following packages:

Both of those packages provide additional instances to Default type class.

data Def Source #

Type tag identifying usage of def from Default.

Instances

Generic Def Source # 

Associated Types

type Rep Def :: * -> * #

Methods

from :: Def -> Rep Def x #

to :: Rep Def x -> Def #

(Applicative f, Default a) => FromEndo (ApplyEndo Def f a) Source # 
type Rep Def Source # 
type Rep Def = D1 (MetaData "Def" "Data.Monoid.Endo.Apply" "endo-0.3.0.0-FDoQmRwl62o5XNvfgqOehr" False) V1
type EndoOperatedOn (ApplyEndo Def f a) Source # 

applyDef :: (Applicative f, Default a) => ApplyEndo Def f a -> f a Source #

Constrained version of applyEndo. Usage example:

applyDef . fromEndo :: (Applicative f, Default a) => Endo a -> f a

applyDef_ :: Default a => ApplyEndo Def Identity a -> a Source #

Same as applyDef, but Applicative functor is specialized to Identity functor and evaluated.

Examples:

>>> fromEndoWith applyDef_ $ foldEndo (+1) [(*10), (+42)] :: Int
421
>>> fromEndoWith applyDef_ $ dualFoldEndo (+1) [(*10), (+42)] :: Int
52

joinApplyDef :: (Monad m, Default a) => m (ApplyEndo Def m a) -> m a Source #

Evaluates ApplyEndo in a Monad by joining it with the monad it contains. It can be also viewed as a variant of applyDef defined as:

joinApplyDef = (>>= applyDef)

ApplyEndo Reader

data Reader Source #

Type tag identifying usage of asks operation in FromEndo instance of ApplyEndo.

Instances

Generic Reader Source # 

Associated Types

type Rep Reader :: * -> * #

Methods

from :: Reader -> Rep Reader x #

to :: Rep Reader x -> Reader #

MonadReader r m => FromEndo (ApplyEndo Reader m r) Source #

Evaluates ApplyEndo in terms of asks operation:

fromEndo = ApplyEndo . asks . appEndo
type Rep Reader Source # 
type Rep Reader = D1 (MetaData "Reader" "Data.Monoid.Endo.Apply" "endo-0.3.0.0-FDoQmRwl62o5XNvfgqOehr" False) V1
type EndoOperatedOn (ApplyEndo Reader m r) Source # 

applyReader :: MonadReader r m => ApplyEndo Reader m r -> m r Source #

Evaluates ApplyEndo in terms of asks operation.

This (->) r is a valid MonadReader instance, therefore, this is a valid use case:

>>> (applyReader . fromEndo $ foldEndo (*10) (+1)) 0 :: Int
10

applyReaderWith :: MonadReader r m => (m r -> a) -> ApplyEndo Reader m r -> a Source #

Evaluates ApplyEndo in terms of asks operation and then evaluates the resalt using provided function.

This (->) r is a valid MonadReader instance, therefore, this is a valid use case:

>>> applyReaderWith ($ 0) . fromEndo $ foldEndo (*10) (+1) :: Int
10

joinApplyReader :: MonadReader r m => m (ApplyEndo Reader m r) -> m r Source #

Evaluates ApplyEndo in a Monad by joining it with the monad it contains. It can be also viewed as a variant of applyReader defined as:

joinApplyReader = (>>= applyReader)

ApplyEndo Modify

data Modify Source #

Type tag identifying usage of state operation in FromEndo instance of ApplyEndo.

Instances

Generic Modify Source # 

Associated Types

type Rep Modify :: * -> * #

Methods

from :: Modify -> Rep Modify x #

to :: Rep Modify x -> Modify #

MonadState s m => FromEndo (ApplyEndo Modify m s) Source #

Evaluates ApplyEndo in terms of state operation:

fromEndo e = ApplyEndo . state $ \s ->
    let s' = appEndo e s in (s', s')
type Rep Modify Source # 
type Rep Modify = D1 (MetaData "Modify" "Data.Monoid.Endo.Apply" "endo-0.3.0.0-FDoQmRwl62o5XNvfgqOehr" False) V1
type EndoOperatedOn (ApplyEndo Modify m s) Source # 

applyModify :: MonadState s m => ApplyEndo Modify m s -> m s Source #

Evaluates ApplyEndo in terms of state operation.

joinApplyModify :: MonadState s m => m (ApplyEndo Modify m s) -> m s Source #

Evaluates ApplyEndo in a Monad by joining it with the monad it contains. It can be also viewed as a variant of applyModify defined as:

joinApplyModify = (>>= applyModify)

ApplyEndo Modify'

data Modify' Source #

Same as Modify, but strictness is implied.

Instances

Generic Modify' Source # 

Associated Types

type Rep Modify' :: * -> * #

Methods

from :: Modify' -> Rep Modify' x #

to :: Rep Modify' x -> Modify' #

MonadState s m => FromEndo (ApplyEndo Modify' m s) Source #

Evaluates ApplyEndo in terms of state operation:

fromEndo (Endo f) = ApplyEndo . state $ \s ->
    let s' = f s in s' `seq` (s', s')
type Rep Modify' Source # 
type Rep Modify' = D1 (MetaData "Modify'" "Data.Monoid.Endo.Apply" "endo-0.3.0.0-FDoQmRwl62o5XNvfgqOehr" False) V1
type EndoOperatedOn (ApplyEndo Modify' m s) Source # 

applyModify' :: MonadState r m => ApplyEndo Modify' m () -> m () Source #

Evaluates ApplyEndo in terms of state operation.

joinApplyModify' :: MonadState r m => m (ApplyEndo Modify' m r) -> m r Source #

Evaluates ApplyEndo in a Monad by joining it with the monad it contains. It can be also viewed as a variant of applyModify' defined as:

joinApplyModify' = (>>= applyModify')