BoundedModule

PackageReified.Refinements
Operations over values that carry their permitted range.

Summary

NameSignatureSynopsis
clampBounded.clamp bounds valueRestricts a value into the bounds.
createBounded.create bounds valueAdmits a value only when it already lies within the bounds.
refinementBounded.refinement boundsReturns a refinement admitting values within the supplied bounds.
valueBounded.value inputReturns the underlying value.
boundsBounded.bounds inputReturns the interval the value is constrained to.
isAtBoundBounded.isAtBound inputReturns whether the value sits on either bound.
mapBounded.map mapping inputApplies a mapping and re-clamps into the same bounds, so the invariant survives a mapping that would otherwise leave the range.
withBoundsBounded.withBounds newBounds inputMoves a value into different bounds, clamping as needed.

clamp

Bounded.clamp bounds value
Member
Restricts a value into the bounds. Total — this is the constructor to reach for first, because an out-of-range input has an obvious correct answer.

Parameters

NameTypeDescription
boundsInterval<'a>
value'a

Returns

Bounded<'a>

create

Bounded.create bounds value
Member
Admits a value only when it already lies within the bounds.

Parameters

NameTypeDescription
boundsInterval<'value>
value'value

Returns

Result<Bounded<'value>, Violation>

refinement

Bounded.refinement bounds
Member
Returns a refinement admitting values within the supplied bounds.

Parameters

NameTypeDescription
boundsInterval<'value>

Returns

Refinement<'value, Bounded<'value>>

value

Bounded.value input
Member
Returns the underlying value.

Parameters

NameTypeDescription
inputBounded<'value>

Returns

'value

bounds

Bounded.bounds input
Member
Returns the interval the value is constrained to.

Parameters

NameTypeDescription
inputBounded<'value>

Returns

Interval<'value>

isAtBound

Bounded.isAtBound input
Member
Returns whether the value sits on either bound.

Parameters

NameTypeDescription
inputBounded<'value>

Returns

bool

map

Bounded.map mapping input
Member
Applies a mapping and re-clamps into the same bounds, so the invariant survives a mapping that would otherwise leave the range.

Parameters

NameTypeDescription
mapping'value -> 'value
inputBounded<'value>

Returns

Bounded<'value>

withBounds

Bounded.withBounds newBounds input
Member
Moves a value into different bounds, clamping as needed.

Parameters

NameTypeDescription
newBoundsInterval<'value>
inputBounded<'value>

Returns

Bounded<'value>