IntervalModule

PackageReified.Refinements
Operations over inclusive ranges of ordered values.

Summary

NameSignatureSynopsis
singletonInterval.singleton valueBuilds the interval containing exactly one value.
betweenInterval.between first secondBuilds the smallest interval containing both values, ordering them as needed.
createInterval.create lower upperBuilds an interval from a pair the caller asserts is already ordered, failing when it is not.
lowerInterval.lower intervalReturns the inclusive lower bound.
upperInterval.upper intervalReturns the inclusive upper bound.
toPairInterval.toPair intervalReturns the bounds as a pair.
isSingletonInterval.isSingleton intervalReturns whether the interval contains exactly one value.
containsInterval.contains value intervalReturns whether the value lies within the inclusive bounds.
containsIntervalInterval.containsInterval inner outerReturns whether every value of the inner interval lies within the outer one.
overlapsInterval.overlaps first secondReturns whether the two intervals share at least one value.
intersectInterval.intersect first secondReturns the shared portion of two intervals, or None when they are disjoint.
unionInterval.union first secondReturns the combined interval when the two overlap, or None when a gap between them would have to be invented.
spanInterval.span first secondReturns the smallest interval containing both inputs, gap included.
extendToInterval.extendTo value intervalReturns the smallest interval containing the input and the value.
ofNonEmptyListInterval.ofNonEmptyList valuesReturns the smallest interval containing every supplied value.
clampInterval.clamp value intervalRestricts a value to the interval's bounds.
mapMonotonicInterval.mapMonotonic mapping intervalApplies a mapping to both bounds.
toConstraintInterval.toConstraint intervalReturns the portable constraint that admits exactly this interval's values.
durationInterval.duration intervalReturns how long an interval of instants lasts.
widthIntInterval.widthInt intervalReturns the distance between the bounds.
widthDecimalInterval.widthDecimal intervalReturns the distance between the bounds.
refinementInterval.refinement intervalReturns a refinement admitting values that lie within the interval.

singleton

Interval.singleton value
Member
Builds the interval containing exactly one value. Total.

Parameters

NameTypeDescription
value'a

Returns

Interval<'a>

between

Interval.between first second
Member
Builds the smallest interval containing both values, ordering them as needed. Total — this is the constructor to reach for first.

Parameters

NameTypeDescription
first'a
second'a

Returns

Interval<'a>

create

Interval.create lower upper
Member
Builds an interval from a pair the caller asserts is already ordered, failing when it is not. Use this at a boundary, where an inverted pair is a caller error worth reporting rather than silently repairing; use between when either order is acceptable input.

Parameters

NameTypeDescription
lower'value
upper'value

Returns

Result<Interval<'value>, Violation>

lower

Interval.lower interval
Member
Returns the inclusive lower bound.

Parameters

NameTypeDescription
intervalInterval<'value>

Returns

'value

upper

Interval.upper interval
Member
Returns the inclusive upper bound.

Parameters

NameTypeDescription
intervalInterval<'value>

Returns

'value

toPair

Interval.toPair interval
Member
Returns the bounds as a pair.

Parameters

NameTypeDescription
intervalInterval<'value>

Returns

'value * 'value

isSingleton

Interval.isSingleton interval
Member
Returns whether the interval contains exactly one value.

Parameters

NameTypeDescription
intervalInterval<'value>

Returns

bool

contains

Interval.contains value interval
Member
Returns whether the value lies within the inclusive bounds.

Parameters

NameTypeDescription
value'value
intervalInterval<'value>

Returns

bool

containsInterval

Interval.containsInterval inner outer
Member
Returns whether every value of the inner interval lies within the outer one.

Parameters

NameTypeDescription
innerInterval<'value>
outerInterval<'value>

Returns

bool

overlaps

Interval.overlaps first second
Member
Returns whether the two intervals share at least one value.

Parameters

NameTypeDescription
firstInterval<'value>
secondInterval<'value>

Returns

bool

intersect

Interval.intersect first second
Member
Returns the shared portion of two intervals, or None when they are disjoint. The option is the honest representation of an empty result.

Parameters

NameTypeDescription
firstInterval<'value>
secondInterval<'value>

Returns

Interval<'value> option

union

Interval.union first second
Member
Returns the combined interval when the two overlap, or None when a gap between them would have to be invented. Use span to close the gap instead.

Parameters

NameTypeDescription
firstInterval<'value>
secondInterval<'value>

Returns

Interval<'value> option

span

Interval.span first second
Member
Returns the smallest interval containing both inputs, gap included. Total.

Parameters

NameTypeDescription
firstInterval<'value>
secondInterval<'value>

Returns

Interval<'value>

extendTo

Interval.extendTo value interval
Member
Returns the smallest interval containing the input and the value. Total.

Parameters

NameTypeDescription
value'value
intervalInterval<'value>

Returns

Interval<'value>

ofNonEmptyList

Interval.ofNonEmptyList values
Member
Returns the smallest interval containing every supplied value. Total.

Parameters

NameTypeDescription
valuesNonEmptyList<'value>

Returns

Interval<'value>

clamp

Interval.clamp value interval
Member
Restricts a value to the interval's bounds. Total.

Parameters

NameTypeDescription
value'value
intervalInterval<'value>

Returns

'value

mapMonotonic

Interval.mapMonotonic mapping interval
Member
Applies a mapping to both bounds. The result is re-ordered, so a mapping that reverses the ordering still yields a well-formed interval.

Parameters

NameTypeDescription
mapping'value -> 'a
intervalInterval<'value>

Returns

Interval<'a>

toConstraint

Interval.toConstraint interval
Member
Returns the portable constraint that admits exactly this interval's values.

Parameters

NameTypeDescription
intervalInterval<'value>

Returns

Constraint<'value>

duration

Interval.duration interval
Member
Returns how long an interval of instants lasts. Total and non-negative.

Parameters

NameTypeDescription
intervalInterval<DateTimeOffset>

Returns

TimeSpan

widthInt

Interval.widthInt interval
Member
Returns the distance between the bounds. Total, and widened to 64 bits because the width of Int32.MinValue .. Int32.MaxValue does not fit an int.

Parameters

NameTypeDescription
intervalInterval<int>

Returns

int64

widthDecimal

Interval.widthDecimal interval
Member
Returns the distance between the bounds. Never negative.

Parameters

NameTypeDescription
intervalInterval<decimal>

Returns

decimal

refinement

Interval.refinement interval
Member
Returns a refinement admitting values that lie within the interval.

Parameters

NameTypeDescription
intervalInterval<'value>

Returns

Refinement<'value, 'value>