FoldLaws

dev.constructive.eo.laws.FoldLaws
trait FoldLaws[S, A, F[_, _]]

Law equations for a Fold[S, A] — a read-only optic whose carrier F has ForgetfulFold[F] and whose write-side is pinned to Unit.

These laws encode the two universal properties of any monoidal fold — foldMap(const(mempty)) collapses to mempty, and foldMap is a monoid homomorphism in the target monoid. The homomorphism property is stated here (additive Int monoid, sufficient to witness the law); see also dev.constructive.eo.laws.eo.FoldMapHomomorphismLaws which states it for any optic with ForgetfulFold[F] and is reused by Traversal / Lens. FoldLaws re-states the empty-constant variant here because it is a genuine stand-alone property of Fold that does not need the homomorphism law's two-function phrasing.

Note: FoldLaws does not include a foldMap consistency check against an externally-supplied Foldable[F]. For Fold.apply[F, A] that consistency is a corollary of how the carrier Forget[F] wires its ForgetfulFold instance through Foldable[F].foldMap. Users who want that check should exercise it as a spec-level property test against the concrete constructor.

Attributes

Source
FoldLaws.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Abstract methods

def fold: Optic[S, Unit, A, Unit, F]

The optic under test.

The optic under test.

Attributes

Source
FoldLaws.scala

Concrete methods

def foldMapEmpty(s: S)(using ForgetfulFold[F]): Boolean

foldMap(const(mempty))(s) == mempty for any source s.

foldMap(const(mempty))(s) == mempty for any source s.

Attributes

Source
FoldLaws.scala
def foldMapHomomorphism(s: S, f: A => Int, g: A => Int)(using ForgetfulFold[F]): Boolean

Monoid homomorphism on the target monoid (tested at Int).

Monoid homomorphism on the target monoid (tested at Int).

Attributes

Source
FoldLaws.scala