Abstract supertype of categories whose elements may be iterated. An iterable category need not be finite, but its elements must at least be countable. There may not be a well-defined iteration order, and so the order of iterated elements may not be stable.
The type Iterable<Element,Null>
, usually abbreviated
{Element*}
represents a possibly-empty iterable
container. The type Iterable<Element,Nothing>
,
usually abbreviated {Element+}
represents a nonempty
iterable container.
An instance of Iterable
may be constructed by
surrounding a value list in braces:
{String+} words = { "hello", "world" };
An instance of Iterable
may be iterated using a for
loop:
for (c in "hello world") { ... }
Iterable
and its subtypes define various operations
that return other iterable objects. Such operations
come in two flavors:
Lazy operations are preferred, because they can be efficiently chained. For example:
string.filter((Character c) => c.letter) .map((Character c) => c.uppercased)
is much less expensive than:
string.select((Character c) => c.letter) .collect((Character c) => c.uppercased)
Furthermore, it is always easy to produce a new immutable iterable object given the view produced by a lazy operation. For example:
[ *string.filter((Character c) => c.letter) .map((Character c) => c.uppercased) ]
Lazy operations normally return an instance of
Iterable
or Map
.
However, there are certain scenarios where an eager operation is more useful, more convenient, or no more expensive than a lazy operation, including:
Eager operations normally return a sequence.
Attributes | |
coalesced | Source Code shared default {<Element&Object>*} coalesced The non-null elements of this |
cycled | Source Code A non-finite iterable object that produces the elements of this iterable object, repeatedly. See also: cycle |
empty | Source Code shared default Boolean empty Determines if the iterable object is empty, that is to say, if the iterator returns no elements. |
first | Source Code shared default Absent|Element first The first element returned by the iterator, if any,
of |
indexed | Source Code All entries of form { "hello", null, "world" }.indexed results in an iterable object with the entries
|
last | Source Code shared default Absent|Element last The last element returned by the iterator, if any,
of |
rest | Source Code Returns an iterable object containing all but the first element of this container. |
sequence | Source Code A sequence containing the elements returned by the iterator. |
size | Source Code shared default Integer size The number of elements returned by the iterator of this iterable object, if the iterator terminates. In the case of an iterable whose elements are not countable, this operation never terminates. |
string | Source Code shared actual default String string A string of form Refined declaration: string |
Inherited Attributes |
Attributes inherited from: Object |
Methods | |
any | Source Code Return Parameters:
|
by | Source Code Produce an (0..10).by(3) results in an iterable object with the elements
Throws:
|
chain | Source Code shared default Iterable<Element|Other,Absent&OtherAbsent> chain<Other, OtherAbsent>(Iterable<Other,OtherAbsent> other) The elements of this iterable object, in their original order, followed by the elements of the given iterable object also in their original order. |
collect | Source Code A sequence containing the results of applying the
given mapping to the elements of this container. An
eager counterpart to Parameters:
See also: map |
contains | Source Code Determines if the given value belongs to this
For most Refined declaration: contains |
count | Source Code Return the number of elements in this Parameters:
|
cycle | Source Code |
defaultNullElements | Source Code shared default Iterable<Element&Object|Default,Absent> defaultNullElements<Default>(Default defaultValue) An Parameters:
|
every | Source Code Return Parameters:
|
filter | Source Code An Parameters:
See also: select |
find | Source Code The first element which satisfies the given
predicate, if any, or Parameters:
|
findLast | Source Code The last element which satisfies the given
predicate, if any, or Parameters:
|
fold | Source Code shared default Result fold<Result>(Result initial, Result accumulating(Result partial, Element elem)) The result of applying the accumulating function to each element of this container in turn. Parameters:
|
following | Source Code An |
iterator | Source Code An iterator for the elements belonging to this container. |
longerThan | Source Code Determines if this iterable object has more elements than the given length. This is an efficient operation for iterable objects with many elements. See also: size |
map | Source Code An Parameters:
See also: collect |
repeat | Source Code Returns a list formed by repeating the elements of this
iterable object the given number of times, or an empty
list if See also: cycle |
select | Source Code A sequence containing the elements of this
container that satisfy the given predicate. An
eager counterpart to Parameters:
See also: filter |
shorterThan | Source Code Determines if this iterable object has fewer elements than the given length. This is an efficient operation for iterable objects with many elements. See also: size |
skipping | Source Code Produce an |
skippingWhile | Source Code Produce an |
sort | Source Code A sequence containing the elements of this container, sorted according to a function imposing a partial order upon the elements. For convenience, the functions "Hello World!".sort(byIncreasing((Character c) => c.lowercased)) This operation is eager by nature. Parameters:
See also: byIncreasing, byDecreasing |
taking | Source Code Produce an |
takingWhile | Source Code Produce an |
Inherited Methods |
Methods inherited from: Object |
Methods inherited from: Category |