Initializer
Singleton(Element element)
Attributes
coalescedSource Codeshared actual Singleton<Element&Object>|[] coalesced

The non-null elements of this stream, in the order in which they occur in this stream. For null elements of the original stream, there is no entry in the resulting stream.

For example, the expression

{ "123", "abc", "456"}.map(parseInteger).coalesced

results in the stream { 123, 456 }.

cycledSource Codeshared actual {Element+} cycled

An infinite stream that produces the element of this singleton, repeatedly.

For example, the expression

Singleton(null).cycled.take(4)

evaluates to the stream { null, null, null, null }.

distinctSource Codeshared actual Singleton<Element> distinct

This singleton.

firstSource Codeshared actual Element first

Returns the element contained in this Singleton.

Refines Sequence.first ultimately refines Iterable.first
hashSource Codeshared actual Integer hash

The hash value of the value, which allows the value to be an element of a hash-based set or key of a hash-based map. Implementations must respect the constraint that:

  • if x==y then x.hash==y.hash.

Therefore, a class which refines Object.equals() must also refine hash.

In general, hash values vary between platforms and between executions of the same program.

Note that when executing on a Java Virtual Machine, the 64-bit Integer value returned by an implementation of hash is truncated to a 32-bit integer value by removal of the 32 highest order bits, before returning the value to the caller.

Refines List.hash ultimately refines Object.hash
indexedSource Codeshared actual {<Integer->Element>+} indexed

A stream containing all entries of form index->element where element is an element of this stream, and index is the position at which element occurs in this stream, ordered by increasing index.

For example, the expression

{ "hello", null, "world" }.indexed

results in the stream { 0->"hello", 1->null, 2->"world" }.

lastSource Codeshared actual Element last

Returns the element contained in this Singleton.

Refines Sequence.last ultimately refines Iterable.last
lastIndexSource Codeshared actual Integer lastIndex

Returns 0.

Refines Sequence.lastIndex ultimately refines List.lastIndex
pairedSource Codeshared actual [] paired

An empty stream.

restSource Codeshared actual [] rest

Returns Empty.

Refines Sequence.rest ultimately refines Iterable.rest
reversedSource Codeshared actual Singleton<Element> reversed

Return this singleton.

Refines Sequence.reversed ultimately refines List.reversed
sizeSource Codeshared actual Integer size

Returns 1.

Refines Sequence.size ultimately refines Iterable.size
stringSource Codeshared actual String string

A developer-friendly string representing the instance. Concatenates the name of the concrete class of the instance with the hash of the instance. Subclasses are encouraged to refine this implementation to produce a more meaningful representation.

Refines Sequence.string ultimately refines Object.string
Inherited Attributes
Attributes inherited from: Object
Attributes inherited from: Collection<Element>
Attributes inherited from: Correspondence<Key,Item>
Attributes inherited from: Iterable<Element,Absent>
Attributes inherited from: List<Element>
Attributes inherited from: [Element+]
Attributes inherited from: Element[]
Methods
anySource Codeshared actual Boolean any(Boolean selecting(Element e))

Determines if there is at least one element of this stream that satisfies the given predicate function. If the stream is empty, returns false. For an infinite stream, this operation might not terminate.

Refines Iterable.any
chainSource Codeshared actual {Element|Other+} chain<Other, OtherAbsent>(Iterable<Other,OtherAbsent> other)
given OtherAbsent satisfies Null

The elements of this stream, in the order in which they occur in this stream, followed by the elements of the given stream in the order in which they occur in the given stream.

For example, the expression

(1..3).chain("abc")

evaluates to the stream { 1, 2, 3, 'a', 'b', 'c' }.

cloneSource Codeshared actual Singleton<Element> clone()

Returns a Singleton with the same element.

Refines Sequence.clone ultimately refines Collection.clone
collectSource Codeshared actual Singleton<Result> collect<Result>(Result collecting(Element element))

Produce a new sequence containing the results of applying the given mapping to the elements of this stream.

This operation is an eager counterpart to Iterable.map(). For any stream it, and mapping f:

it.collect(f) == [*it.map(f)]
Refines Sequence.collect ultimately refines Iterable.collect
containsSource Codeshared actual Boolean contains(Object element)

Returns true if the specified element is this Singleton's element.

Refines Sequence.contains ultimately refines Category.contains
countSource Codeshared actual Integer count(Boolean selecting(Element element))

Returns 1 if this Singleton's element satisfies the predicate, or 0 otherwise.

eachSource Codeshared actual void each(void step(Element element))

Call the given function for each element of this stream, passing the elements in the order they occur in this stream.

For example:

words.each((word) {
    print(word.lowercased);
    print(word.uppercased);
});

Has the same effect as the following for loop:

for (word in words) {
    print(word.lowercased);
    print(word.uppercased);
}

For certain streams this method is highly efficient, surpassing the performance of for loops on the JVM. Thus, each() is sometimes preferred in highly performance-critical low-level code.

equalsSource Codeshared actual Boolean equals(Object that)

A Singleton can be equal to another List if that List has only one element which is equal to this Singleton's element.

Refines List.equals ultimately refines Object.equals
everySource Codeshared actual Boolean every(Boolean selecting(Element e))

Determines if all elements of this stream satisfy the given predicate function. If the stream is empty, return true. For an infinite stream, this operation might not terminate.

filterSource Codeshared actual Singleton<Element>|[] filter(Boolean selecting(Element e))

Produces a stream containing the elements of this stream that satisfy the given predicate function.

For any empty stream, filter() returns an empty stream:

{}.filter(p) == {}

For any nonempty stream it, and predicate p, the result of filter() may be obtained according to this recursive definition:

it.filter(p) == { if (p(it.first)) it.first }.chain(it.rest.filter(f))

Alternatively, and in practice, filter() may be defined by this comprehension:

it.filter(p) == { for (e in it) if (p(e)) e };

For example, the expression

(1..100).filter(13.divides)

results in the stream { 13, 26, 39, 52, 65, 78, 91 }.

findSource Codeshared actual Element? find(Boolean selecting(Element&Object e))

The first element of this stream which satisfies the given predicate function, if any, or null if there is no such element. For an infinite stream, this method might not terminate.

For example, the expression

(-10..10).find(Integer.positive)

evaluates to 1.

Refines Sequence.find ultimately refines Iterable.find
findLastSource Codeshared actual Element? findLast(Boolean selecting(Element&Object e))

The last element of this stream which satisfies the given predicate function, if any, or null if there is no such element. For an infinite stream, this method will not terminate.

For example, the expression

(-10..10).findLast(3.divides)

evaluates to 9.

Refines Sequence.findLast ultimately refines Iterable.findLast
foldSource Codeshared actual Result fold<Result>(Result initial)(Result accumulating(Result partial, Element e))

Beginning with a given initial value, apply the given combining function to each element of this stream in turn, progressively accumulating a single result.

For an empty stream, fold() returns the given initial value z:

{}.fold(z)(f) == z

For a given nonempty stream it, initial value z, and combining function f, the result of fold() is obtained according to the following recursive definition:

it.fold(z)(f) == f(it.exceptLast.fold(z)(f), it.last)

For example, the expression

(1..100).fold(0)(plus)

results in the integer 5050.

followSource Codeshared actual {Other|Element+} follow<Other>(Other head)

A stream with given head, followed by the element of this singleton.

For example, the expression

Singleton(1).follow(2)

evaluates to the stream { 2, 1 }.

getFromFirstSource Codeshared actual Element? getFromFirst(Integer index)

Returns the contained element, if the specified index is 0.

Refines List.getFromFirst ultimately refines Iterable.getFromFirst
interposeSource Codeshared actual Singleton<Element> interpose<Other>(Other element, Integer step)

This singleton.

Parameters:
  • step
    • step must be strictly positive

iteratorSource Codeshared actual Iterator<Element> iterator()

An iterator for the elements belonging to this stream.

Refines List.iterator ultimately refines Iterable.iterator
mapSource Codeshared actual Singleton<Result> map<Result>(Result collecting(Element e))

Produces a stream containing the results of applying the given mapping to the elements of this stream.

For any empty stream, map() returns an empty stream:

{}.map(f) == {}

For any nonempty stream it, and mapping function f, the result of map() may be obtained according to this recursive definition:

it.map(f).first == f(it.first)
it.map(f).rest == it.rest.map(f)

Alternatively, and in practice, map() may be defined by this comprehension:

it.map(f) == { for (e in it) f(e) }

For example, the expression

(0..4).map(10.power)

results in the stream { 1, 10, 100, 1000, 10000 }.

Refines Iterable.map
measureSource Codeshared actual []|Singleton<Element> measure(Integer from, Integer length)

Returns a Singleton if the given starting index is 0 and the given length is greater than 0. Otherwise, returns an instance of Empty.

Refines Sequence.measure ultimately refines Ranged.measure
reduceSource Codeshared actual Element reduce<Result>(Result accumulating(Result|Element partial, Element e))

Beginning with the Iterable.first element of this stream, apply the given combining function to each element of this stream in turn, progressively accumulating a single result.

For an empty stream, reduce() always returns null.

For a stream with one element, reduce() returns that element:

{ first }.reduce(f) == first

For a given stream it with more than one element, and combining function f, the result of reduce() is obtained according to the following recursive definition:

it.reduce(f) == f(it.exceptLast.reduce(f), it.last)

For example, the expression

(1..100).reduce(plus)

results in the integer 5050.

selectSource Codeshared actual Singleton<Element>|[] select(Boolean selecting(Element element))

Produce a new sequence containing all elements of this stream that satisfy the given predicate function, in the order in which they occur in this stream.

This operation is an eager counterpart to Iterable.filter(). For any stream it, and predicate p:

it.select(p) == [*it.filter(p)]
skipSource Codeshared actual Singleton<Element>|[] skip(Integer skipping)

Produces a stream containing the elements of this stream, after skipping the first skipping elements produced by its iterator.

If this stream does not contain more elements than the specified number of elements to skip, the resulting stream has no elements. If the specified number of elements to skip is zero or fewer, the resulting stream contains the same elements as this stream.

sortSource Codeshared actual Singleton<Element> sort(Comparison comparing(Element a, Element b))

Produce a new sequence containing the elements of this stream, sorted according to the given comparator function imposing a partial order upon the elements of the stream.

For convenience, the functions byIncreasing() and byDecreasing() produce suitable comparator functions.

For example, this expression

"Hello World!".sort(byIncreasing(Character.lowercased))

evaluates to the sequence [ , !, d, e, H, l, l, l, o, o, r, W].

This operation is eager by nature.

Note that the toplevel function sort() may be used to sort a stream of Comparable values according to the natural order of its elements.

Refines Sequence.sort ultimately refines Iterable.sort
spanSource Codeshared actual []|Singleton<Element> span(Integer from, Integer to)

Returns a Singleton if the given starting index is 0. Otherwise, returns an instance of Empty.

Refines Sequence.span ultimately refines Ranged.span
spanFromSource Codeshared actual []|Singleton<Element> spanFrom(Integer 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 Iterable.iterator() of the stream.

When the given index does not belong to this ranged stream, the behavior is implementation dependent.

Refines Sequence.spanFrom ultimately refines Ranged.spanFrom
spanToSource Codeshared actual []|Singleton<Element> spanTo(Integer 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 Iterable.iterator() of the stream.

When the given index does not belong to this ranged stream, the behavior is implementation dependent.

Refines Sequence.spanTo ultimately refines Ranged.spanTo
takeSource Codeshared actual Singleton<Element>|[] take(Integer taking)

Produces a stream containing the first taking elements of this stream.

If the specified number of elements to take is larger than the number of elements of this stream, the resulting stream contains the same elements as this stream. If the specified number of elements to take is fewer than one, the resulting stream has no elements.

Inherited Methods
Methods inherited from: Object
Methods inherited from: Category<Element>
Methods inherited from: Collection<Element>
Methods inherited from: Correspondence<Key,Item>
Methods inherited from: Iterable<Element,Absent>
Methods inherited from: List<Element>
Methods inherited from: Ranged<Index,Element,Subrange>
Methods inherited from: [Element+]
Methods inherited from: Element[]