This typeclass provides support for the PRange.size
function.
The returned size should be equal to the number of elements returned by toList
. This condition
is captured by the typeclass LawfulRangeSize
.
Returns the number of elements starting from
init
that satisfy the given upper bound.
Instances
This typeclass ensures that a RangeSize
instance returns the correct size for all ranges.
- size_eq_zero_of_not_satisfied (upperBound : Bound su α) (init : α) (h : ¬SupportsUpperBound.IsSatisfied upperBound init) : RangeSize.size upperBound init = 0
If the smallest value in the range is beyond the upper bound, the size is zero.
- size_eq_one_of_succ?_eq_none (upperBound : Bound su α) (init : α) (h : SupportsUpperBound.IsSatisfied upperBound init) (h' : UpwardEnumerable.succ? init = none) : RangeSize.size upperBound init = 1
If the smallest value in the range satisfies the upper bound and has no successor, the size is one.
- size_eq_succ_of_succ?_eq_some {a : α} (upperBound : Bound su α) (init : α) (h : SupportsUpperBound.IsSatisfied upperBound init) (h' : UpwardEnumerable.succ? init = some a) : RangeSize.size upperBound init = RangeSize.size upperBound a + 1
If the smallest value in the range satisfies the upper bound and has a successor, the size is one larger than the size of the range starting at the successor.
Instances
Checks whether the range contains any value.
This function returns a meaningful value for all range types defined by the standard library
and for all range types that satisfy the properties encoded in the LawfulUpwardEnumerable
,
LawfulUpwardEnumerableLowerBound
and LawfulUpwardEnumerableUpperBound
typeclasses.
Equations
- r.isEmpty = Option.all (fun (x : α) => !decide (Std.PRange.SupportsUpperBound.IsSatisfied r.upper x)) (Std.PRange.BoundedUpwardEnumerable.init? r.lower)