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
operation introduces a split, since only transformations occurring
outside the freeze should be applied to attributes.
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;
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
Split uses the asymmetric constructor
Cut the symmetric constructor
:||:, to emphasize the inherent
Split and symmetry of
Split keeps only
the rightmost split and combines everything on the left;
keeps the outermost splits and throws away everything in between.
|Show m => Show (Split m)|
|(Semigroup m, Monoid m) => Monoid (Split m)|
|Semigroup m => Semigroup (Split m)|
|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.
A convenient name for
mempty :| mempty, so
M a <> split <>
M b == a :| b.