AffineFoldLaws
Law equations for an AffineFold[S, A] — a read-only 0-or-1 focus optic whose carrier is Affine and whose write side is pinned to Unit.
AffineFold's observable surface is two operations — getOption and foldMap — and the laws below pin down their agreement:
getOptionConsistent:getOptionandfoldMapagree on the single hit. Phrased viafoldMap(List(_)): the full fold collects every focus into a list; for AffineFold that list has zero or one element, whose head is exactly thegetOptionresult.missIsEmpty: whengetOption(s)isNone,foldMap(f)(s)must equalMonoid.emptyunder every monoidM. Tested atInt(additive) for scalacheck coverage.hitIsSingleton: whengetOption(s)isSome(a),foldMap(f)(s)must equalf(a)under every monoid. Tested atIntas above.
Laws (2) and (3) are the two "branches" of an invariant that's trivially true by the Affine carrier's ForgetfulFold instance — they're nonetheless worth stating because the AffineFold's value is exactly that a user-supplied partial matcher fits the miss/hit contract. A constructor that returned the wrong branch would fail law (2) or (3) for the wronged input.
Ported from Monocle's monocle.law.AffineFoldLaws (which states getAll.headOption === getOption directly); our phrasing goes through the generic foldMap extension to stay within the existential-optic surface.
Attributes
- Source
- AffineFoldLaws.scala
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any