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

Maintainerdiagrams-discuss@googlegroups.com
Safe HaskellSafe-Inferred

Data.Monoid.Cut

Description

The Cut monoid transformer introduces "cut points" such that all values between any two cut points are thrown away. That is,

 a b c | d e | f g h i | j k  ==  a b c | j k

Synopsis

Documentation

data Cut m Source

A value of type Cut m is either a single m, or a pair of m's separated by a divider. The divider represents a "cut point".

Cut is similar to Data.Monoid.Split, but split keeps only the rightmost divider and accumulates all values, whereas cut always keeps the leftmost and rightmost divider, coalescing them into one and throwing away all the information in between.

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

Uncut m 
m :||: m 

Instances

Show m => Show (Cut m) 
(Semigroup m, Monoid m) => Monoid (Cut m) 
Semigroup m => Semigroup (Cut m)

If m is a Semigroup, then Cut m is a semigroup which contains m as a sub-semigroup, but also contains elements of the form m1 :||: m2. When elements of m combine with such "cut" elements they are combined with the value on the corresponding side of the cut (e.g. (Uncut m1) <> (m1' :||: m2) = (m1 <> m1') :||: m2). When two "cut" elements meet, the two inside values are thrown away and only the outside values are kept.

cut :: Monoid m => Cut mSource

A convenient name for mempty :||: mempty, so composing with cut introduces a cut point. For example, Uncut a <> cut <> Uncut b == a :||: b.