Abstract supertype of ranged streams mapping a range of
discrete indices to elements of the stream, and supporting
operations that produce a subrange of indexed elements. The
type parameter Subrange
abstracts the type of the
resulting subrange. A subrange may be obtained from an
instance of Ranged
using the span and measure
operators.
Often, in a List
or sorted map for example, an index
and its element are distinct values. Sometimes, in a sorted
set for example, the index and element are identical.
The span operator accepts the first and last indices of the subrange.
print("hello world"[0..4]); //prints "hello" print("hello world"[6..6]); //prints "w"
If the last index is smaller than the first index, the subrange is reversed.
print("hello world"[4..0]); //prints "olleh"
If the range of indices identified by the first and last indices is outside the range of indices of this object, an empty subrange is produced.
print("hello world"[-5..-1]); //prints "" print("hello world"[11..11]); //prints ""
The first index may be omitted, implying that the subrange
extends forward from the smallest possible index (in this
case runtime.minIntegerValue
) to the given index.
print("hello world"[...4]) //prints "hello"
If the first index is before the first index of this object, the first index of the object is used.
print("hello world"[-5...]); //prints "hello world"
The last index may be omitted, implying that the subrange
extends forward from the given index to the largest
possible index (in this case runtime.maxIntegerValue
).
print("hello world"[6...]) //prints "world"
If the last index is after the last index of this object, an empty subrange is produced. (A reversed subrange is never produced.)
print("hello world"[11...]); //prints ""
The measure operator accepts the first index and maximum length of the subrange.
print("hello world"[6:5]) //prints "world" print("hello world"[6:0]) //prints ""
If the length is nonpositive, the subrange is empty. If the range of indices identified by the first index and length is outside the range of indices of this object, an empty subrange is produced. (A reversed subrange is never produced.)
print("hello world"[-3:3]) //prints "" print("hello world"[11:3]) //prints "" print("hello world"[6:-3]) //prints ""
The span and measure operations must be consistent. That is,
for every pair of indices x
and y
in the ranged object
ranged
such that y
does not occur before x
and the
span ranged[x..y]
has length n
:
ranged[x..y]==ranged[x:n]
.no type hierarchy
Inherited Attributes |
Attributes inherited from: Object |
Attributes inherited from: Iterable<Element,Absent> |
Methods | |
measure | Source Codeshared formal Subrange measure(Index from, Integer length) Obtain a measure containing the mapped values starting
from the given starting index, with the given
The measure should contain the given number
of elements of this stream, starting from the element
at the given starting index, in the same order
as they are produced by the When the given index does not belong to this ranged object, the behavior is implementation dependent. |
span | Source Codeshared formal Subrange span(Index from, Index to) Obtain a span containing the elements between the two given indices. The span should contain elements of this stream,
starting from the element at the given starting
index, and ending with the element at the given
ending index, in the same order as they are
produced by the When one or both of the given indices does not belong to this ranged stream, the behavior is implementation dependent. |
spanFrom | Source Codeshared formal Subrange spanFrom(Index from) Obtain a span containing the elements between the given starting index and the last index of this ranged object. The span should contain elements of this stream,
starting from the element at the given starting
index, in the same order as they are produced by
the When the given index does not belong to this ranged stream, the behavior is implementation dependent. |
spanTo | Source Codeshared formal Subrange spanTo(Index to) Obtain a span containing the elements between the first index of this ranged stream and given end index. The span should contain elements of this stream, up to
the element at the given ending index, in the
same order as they are produced by the When the given index does not belong to this ranged stream, the behavior is implementation dependent. |
Inherited Methods |
Methods inherited from: Object |
Methods inherited from: Category<Element> |
Methods inherited from: Iterable<Element,Absent> any() , by() , chain() , collect() , contains() , count() , defaultNullElements() , each() , every() , filter() , find() , findLast() , flatMap() , fold() , follow() , frequencies() , getFromFirst() , group() , indexes() , interpose() , iterator() , locate() , locateLast() , locations() , longerThan() , map() , max() , narrow() , partition() , product() , reduce() , repeat() , scan() , select() , sequence() , shorterThan() , skip() , skipWhile() , sort() , spread() , summarize() , tabulate() , take() , takeWhile() |