flux-monoid-0.1.0.0: A monoid for tracking changes

Copyright(c) Chris Penner 2018
LicenseBSD-3-Clause
Stabilitystable
Safe HaskellSafe
LanguageHaskell2010

Data.Monoid.Flux

Description

Flux is a monoid which detects the number of times a value changes across a sequence

getFlux $ foldMap flux ["a", "b", "b", "a"]
2
getFlux $ foldMap flux ["a", "b", "b", "a", "c", "c", "c"]
3

Synopsis

Documentation

data Flux a Source #

Flux is a monoid which counts the number of times an element changes (according to its Eq instance) This is useful for gaining associativity (and its associated performance improvements) for tasks where you'd otherwise use group or groupBy

It also allows usage of change-detection semantics in situations where a Monoid is required; e.g. in a FingerTree

Constructors

Flux 

Fields

Instances

Eq a => Eq (Flux a) Source # 

Methods

(==) :: Flux a -> Flux a -> Bool #

(/=) :: Flux a -> Flux a -> Bool #

Show a => Show (Flux a) Source # 

Methods

showsPrec :: Int -> Flux a -> ShowS #

show :: Flux a -> String #

showList :: [Flux a] -> ShowS #

Eq a => Monoid (Flux a) Source # 

Methods

mempty :: Flux a #

mappend :: Flux a -> Flux a -> Flux a #

mconcat :: [Flux a] -> Flux a #

flux :: a -> Flux a Source #

Embed a single value into a Flux; number of changes starts at 0.