class base range
implements range
private nonnegative the begin
private nonnegative the end
base range(nonnegative the begin, nonnegative the end)
assert the begin <= the end
this • the begin = the begin
this • the end = the end
Start of the range.
implement nonnegative begin()
return the begin
End of the range; greater or equal than start.
implement nonnegative end()
return the end
The number of elements in the collection.
implement nonnegative size()
assert the size is nonnegative
return the size
Specifies whether the collection has zero elements.
implement boolean is empty => the begin == the end
Specifies whether the collection has more than zero elements. Shortcut for !is_empty.
implement boolean is not empty => the begin != the end
Access the first element of the list. Assumes the list is not empty.
implement nonnegative first()
assert is not empty
return the begin
Access the last element of the list. Assumes the list is not empty.
implement nonnegative last()
assert is not empty
result : the end - 1
assert result is nonnegative
return result
Read the list's element for the specified index.
implement implicit readonly reference[nonnegative] get(nonnegative index) pure
result : the begin + index
assert result < the end
return result
Enumerates elements in some collection-defined order. This method returns a snapshot of the collection state, so subsequent mutations of the collection do not cause changes in the returned list.
implement range elements()
return this
Returns an immutable copy of this list.
implement range frozen copy()
return this
implement range skip(nonnegative count)
new begin : the begin + count
assert new begin <= the end
return base range • new(new begin, the end)
implement range slice(nonnegative slice begin, nonnegative slice end)
new begin : the begin + slice begin
new end : the begin + slice end
assert new begin <= new end
return base range • new(new begin, new end)
Returns an immutable list with the order of the elements reversed.
implement immutable list[nonnegative] reverse()
for var value : the end - 1; value >= the begin; value -= 1
assert nonnegative value is nonnegative
resultappend(nonnegative value)
return resultfrozen copy()
Check whether the list has at least one element that satisfies the predicate.
implement boolean has(predicate[nonnegative] the predicate) pure
for var nonnegative value : the begin; value < the end; value += 1
if the predicate(value)
return true
return false