monoid-extras- Various extra monoid-related definitions and utilities
Safe HaskellSafe-Infered



Sometimes we want to accumulate values from some monoid, but have the ability to introduce a "split" which separates values on either side. For example, 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.



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.


M m 
m :| m 


(Semigroup m, Monoid m) => Monoid (Split m) 
Semigroup m => Semigroup (Split m)

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.

Action m n => Action (Split m) n

By default, the action of a split monoid is the same as for the underlying monoid, as if the split were removed.

split :: Monoid m => Split mSource

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

unsplit :: Semigroup m => Split m -> mSource

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