concrete-optics.algebra.structures
Constructors and examples of semigroups, monoids, apply and applicatives.
additive-monoid
The semigroup on numbers whose opearion is addition. Since addition also has a unit, namely 0, this actually defines a monoid.
const-applicative
(const-applicative semigroup)Promotes a semigroup into an apply. If the semigroup is a a monoid then the result is an applicative.
failure?
(failure? x)Checks if the input represents a failure, that it, if it is a map of the form {:failure <report>}.
first-semigroup
The semigroup whose operation picks the first argumet and ignores the second. There is no unit for this operation.
map-failure
(map-failure to-new-failure f)Changes the failure type for a validation function.
mk-apply
(mk-apply fmap binary-lift)(mk-apply fmap binary-lift pure)Wraps a mapping operation and a binary operation lifter as {:fmap fmap :binary-lift binary-lift}. We assume that the wrapped functions satisfy the ‘semimonoidal functor’ laws. If there is also a pure operation which injects a regular value into the context then we assume that the wrapped values form an ‘applicative functor’.
mk-semigroup
(mk-semigroup binary-op)(mk-semigroup binary-op unit)Wraps a binary associative operator as {:binary-op binary-op}. If in addition there is a unit then the result is the map {:binary-op binary-op :unit unit}. If there is a unit, the semigroup is indeed a monoid. A unit should not be encoded by a nil.
validation-applicative
(validation-applicative semigroup)Constructs an applicative where failures are accumulated using the semigroup.
vector-monoid
The semigroup on vectors whose operation is concatenation. Since concatenation has a unit, namely [], this is actually a monoid.