monoid-extras-0.7: Various extra monoid-related definitions and utilities

Copyright | (c) 2011-2015 diagrams-core team (see LICENSE)
License | BSD-style (see LICENSE)
Maintainer | diagrams-discuss@googlegroups.com
Safe Haskell | Safe-Inferred
Language | Haskell2010

Data.Monoid.Split

Description

Sometimes we want to accumulate values from some monoid, but have the ability to introduce a "split" which separates values on either side. Only the rightmost split is kept. For example,

    a b c | d e | f g h == a b c d e | f g h

In the diagrams graphics framework this is used when accumulating transformations to be applied to primitive diagrams: the `freeze` operation introduces a split, since only transformations occurring outside the freeze should be applied to attributes.

Synopsis

- data Split m
  - = M m
  - | m :| m
- split :: Monoid m => Split m
- unsplit :: Semigroup m => Split m -> m

# Documentation

data Split m Source #

A value of type `Split m` is either a single `m`, or a pair of `m`'s separated by a divider. Single `m`'s combine as usual; single `m`'s combine with split values by combining with the value on the appropriate side; when two split values meet only the rightmost split is kept, with both the values from the left split combining with the left-hand value of the right split.

Data.Monoid.Cut is similar, but uses a different scheme for composition. `Split` uses the asymmetric constructor `:|`, and `Cut` the symmetric constructor `:||:`, to emphasize the inherent asymmetry of `Split` and symmetry of `Cut`. `Split` keeps only the rightmost split and combines everything on the left; `Cut` keeps the outermost splits and throws away everything in between.

Constructors

M m |
m :| m infix 5 |

#### Instances

Instances details

Functor Split Source # |
Instance details Defined in Data.Monoid.Split Methods fmap :: (a -> b) -> Split a -> Split b Source # (<$) :: a -> Split b -> Split a Source #
Foldable Split Source # |

Instance details

Defined in Data.Monoid.Split

Methods

fold :: Monoid m => Split m -> m Source #

foldMap :: Monoid m => (a -> m) -> Split a -> m Source #

foldMap' :: Monoid m => (a -> m) -> Split a -> m Source #

foldr :: (a -> b -> b) -> b -> Split a -> b Source #

foldr' :: (a -> b -> b) -> b -> Split a -> b Source #

foldl :: (b -> a -> b) -> b -> Split a -> b Source #

foldl' :: (b -> a -> b) -> b -> Split a -> b Source #

foldr1 :: (a -> a -> a) -> Split a -> a Source #

foldl1 :: (a -> a -> a) -> Split a -> a Source #

toList :: Split a -> [a] Source #

null :: Split a -> Bool Source #

length :: Split a -> Int Source #

elem :: Eq a => a -> Split a -> Bool Source #

maximum :: Ord a => Split a -> a Source #

minimum :: Ord a => Split a -> a Source #

sum :: Num a => Split a -> a Source #

product :: Num a => Split a -> a Source #

Traversable Split Source # |
Instance details Defined in Data.Monoid.Split Methods traverse :: Applicative f => (a -> f b) -> Split a -> f (Split b) Source # sequenceA :: Applicative f => Split (f a) -> f (Split a) Source # mapM :: Monad m => (a -> m b) -> Split a -> m (Split b) Source # sequence :: Monad m => Split (m a) -> m (Split a) Source #
(Semigroup m, Monoid m) => Monoid (Split m) Source # |
Instance details Defined in Data.Monoid.Split Methods mempty :: Split m Source # mappend :: Split m -> Split m -> Split m Source # mconcat :: [Split m] -> Split m Source #
Semigroup m => Semigroup (Split m) Source # | If `m` is a `Semigroup`, then `Split m` is a semigroup which combines values on either side of a split, keeping only the rightmost split.
Instance details Defined in Data.Monoid.Split Methods (<>) :: Split m -> Split m -> Split m Source # sconcat :: NonEmpty (Split m) -> Split m Source # stimes :: Integral b => b -> Split m -> Split m Source #
Data m => Data (Split m) Source # |

Instance details

Defined in Data.Monoid.Split

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Split m -> c (Split m) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Split m) Source #

toConstr :: Split m -> Constr Source #

dataTypeOf :: Split m -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Split m)) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Split m)) Source #

gmapT :: (forall b. Data b => b -> b) -> Split m -> Split m Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Split m -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Split m -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Split m -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Split m -> u Source #

gmapM :: Monad m0 => (forall d. Data d => d -> m0 d) -> Split m -> m0 (Split m) Source #

gmapMp :: MonadPlus m0 => (forall d. Data d => d -> m0 d) -> Split m -> m0 (Split m) Source #

gmapMo :: MonadPlus m0 => (forall d. Data d => d -> m0 d) -> Split m -> m0 (Split m) Source #

Read m => Read (Split m) Source # |
Instance details Defined in Data.Monoid.Split Methods readsPrec :: Int -> ReadS (Split m) Source # readList :: ReadS [Split m] Source # readPrec :: ReadPrec (Split m) Source # readListPrec :: ReadPrec [Split m] Source #
Show m => Show (Split m) Source # |
Instance details Defined in Data.Monoid.Split Methods showsPrec :: Int -> Split m -> ShowS Source # show :: Split m -> String Source # showList :: [Split m] -> ShowS Source #
Eq m => Eq (Split m) Source # |
Instance details Defined in Data.Monoid.Split Methods (==) :: Split m -> Split m -> Bool Source # (/=) :: Split m -> Split m -> Bool Source #
Action m n => Action (Split m) n Source # | By default, the action of a split monoid is the same as for the underlying monoid, as if the split were removed.
Instance details Defined in Data.Monoid.Split Methods act :: Split m -> n -> n Source #

split :: Monoid m => Split m Source #

A convenient name for `mempty :| mempty`, so `M a <> split <> M b == a :| b`.

unsplit :: Semigroup m => Split m -> m Source #

"Unsplit" a split monoid value, combining the two values into one (or returning the single value if there is no split).