<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
Note: Repeated chaining of calls to append methods (appended
,
appendedAll
, lazyAppendedAll
) without forcing any of the
intermediate resulting lazy lists may overflow the stack when
the final result is forced.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
Note: Repeated chaining of calls to append methods (appended
,
appendedAll
, lazyAppendedAll
) without forcing any of the
intermediate resulting lazy lists may overflow the stack when
the final result is forced.
Appends all elements of this lazy list to a string builder using start, end, and separator strings.
Appends all elements of this lazy list to a string builder using start, end, and separator strings.
The written text begins with the string start
and ends with the string end
.
Inside, the string representations (w.r.t. the method toString
)
of all elements of this lazy list are separated by the string sep
.
An undefined state is represented with "<not computed>"
and cycles are represented with "<cycle>"
.
This method evaluates all elements of the collection.
the string builder to which elements are appended.
the starting string.
the separator string.
the ending string.
the string builder b
to which elements were appended.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method does not evaluate any elements further than the first element for which the partial function is defined.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method does not evaluate anything until an operation is performed
on the result (e.g. calling head
or tail
, or checking if it is empty).
Additionally, it preserves laziness for all except the first n
elements.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method does not evaluate anything until an operation is performed
on the result (e.g. calling head
or tail
, or checking if it is empty).
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method does not evaluate anything until an operation is performed
on the result (e.g. calling head
or tail
, or checking if it is empty).
Additionally, it preserves laziness for all elements after the predicate returns false
.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method evaluates all elements of the collection.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method does not evaluate any elements further than the first element matching the predicate.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
LazyList specialization of foldLeft which allows GC to collect along the way.
LazyList specialization of foldLeft which allows GC to collect along the way.
The type of value being accumulated.
The initial value seeded into the function op
.
The operation to perform on successive elements of the LazyList
.
The accumulated value from successive applications of op
.
Evaluates all undefined elements of the lazy list.
Evaluates all undefined elements of the lazy list.
This method detects cycles in lazy lists, and terminates after all elements of the cycle are evaluated. For example:
val ring: LazyList[Int] = 1 #:: 2 #:: 3 #:: ring ring.force ring.toString // prints // // LazyList(1, 2, 3, ...)
This method will *not* terminate for non-cyclic infinite-sized collections.
this
Apply the given function f
to each element of this linear sequence
(while respecting the order of the elements).
Apply the given function f
to each element of this linear sequence
(while respecting the order of the elements).
The treatment to apply to each element.
This function will force the realization of the entire LazyList
unless the f
throws an exception.
Overridden here as final to trigger tail-call optimization, which replaces 'this' with 'tail' at each iteration. This is absolutely necessary for allowing the GC to collect the underlying LazyList as elements are consumed.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
The iterator returned by this method mostly preserves laziness; a single element ahead of the iterator is evaluated.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
The iterator returned by this method preserves laziness; elements are only evaluated individually as needed.
This method preserves laziness; elements are only evaluated individually as needed.
The lazy list resulting from the concatenation of this lazy list with the argument lazy list.
The lazy list resulting from the concatenation of this lazy list with the argument lazy list.
This method preserves laziness; elements are only evaluated individually as needed.
Note: Repeated chaining of calls to append methods (appended
,
appendedAll
, lazyAppendedAll
) without forcing any of the
intermediate resulting lazy lists may overflow the stack when
the final result is forced.
The collection that gets appended to this lazy list
The lazy list containing elements of this lazy list and the iterable object.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
LazyList specialization of reduceLeft which allows GC to collect along the way.
LazyList specialization of reduceLeft which allows GC to collect along the way.
The type of value being accumulated.
The operation to perform on successive elements of the LazyList
.
The accumulated value from successive applications of f
.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method evaluates all elements of the collection.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
(Changed in version 2.9.0) The behavior of scanRight
has changed. The previous behavior can be reproduced with scanRight.reverse.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method does not evaluate anything until an operation is performed
on the result (e.g. calling head
or tail
, or checking if it is empty).
Additionally, it preserves laziness for all but the first from
elements.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
The iterator returned by this method mostly preserves laziness;
size - step max 1
elements ahead of the iterator are evaluated.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method does not evaluate anything until an operation is performed
on the result (e.g. calling head
or tail
, or checking if it is empty).
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
This method preserves laziness; elements are only evaluated individually as needed.
This method preserves laziness; elements are only evaluated individually as needed.
a string representation of this collection. An undefined state is
represented with "<not computed>"
and cycles are represented with "<cycle>"
Examples:
"LazyList(4, <not computed>)"
, a non-empty lazy list ;"LazyList(1, 2, 3, <not computed>)"
, a lazy list with at least three elements ;"LazyList(1, 2, 3, <cycle>)"
, an infinite lazy list that contains
a cycle at the fourth element.(Changed in version 2.9.0) transpose
throws an IllegalArgumentException
if collections are not uniformly sized.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
A collection.WithFilter
which allows GC of the head of lazy list during processing.
A collection.WithFilter
which allows GC of the head of lazy list during processing.
This method is not particularly useful for a lazy list, as filter already preserves laziness.
The collection.WithFilter
returned by this method preserves laziness; elements are
only evaluated individually as needed.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
This class implements an immutable linked list that evaluates elements in order and only when needed. Here is an example:
A
LazyList
, like the one in the example above, may be infinite in length. Aggregate methods, such ascount
,sum
,max
ormin
on such infinite length sequences will not terminate. Filtered infinite lazy lists are also effectively infinite in length.Elements of a
LazyList
are memoized; that is, the value of each element is computed only once. To illustrate, we will alter body of thefibs
value above and take some more values:There are a number of subtle points to the above example.
fibs
is aval
not a method. The memoization of theLazyList
requires us to have somewhere to store the information and aval
allows us to do that.LazyList
is actually being modified during access, this does not change the notion of its immutability. Once the values are memoized they do not change and values that have yet to be memoized still "exist", they simply haven't been realized yet.LazyList
creates a structure much like scala.collection.immutable.List. So long as something is holding on to the head, the head holds on to the tail, and so it continues recursively. If, on the other hand, there is nothing holding on to the head (e.g. we useddef
to define theLazyList
) then once it is no longer being used directly, it disappears.LazyList
, and a lazy list holds its own head. For computations of this sort where memoization is not desired, useIterator
when possible.tail
works at all is of interest. In the definition offibs
we have an initial(0, 1, LazyList(...))
sotail
is deterministic. If we definedfibs
such that only0
were concretely known then the act of determiningtail
would require the evaluation oftail
which would cause an infinite recursion and stack overflow. If we define a definition where the tail is not initially computable then we're going to have an infinite recursion:The definition of
fibs
above creates a larger number of objects than necessary depending on how you might want to implement it. The following implementation provides a more "cost effective" implementation due to the fact that it has a more direct route to the numbers themselves:the type of the elements contained in this lazy list.
"Scala's Collection Library overview" section on
LazyLists
for more information.