final class LazyList[+A] extends AbstractSeq[A] with immutable.LinearSeq[A] with GenericTraversableTemplate[A, LazyList] with LinearSeqOptimized[A, LazyList[A]] with Serializable
This class implements an immutable linked list that evaluates elements in order and only when needed. Here is an example:
import scala.math.BigInt object Main extends App { val fibs: LazyList[BigInt] = BigInt(0) #:: BigInt(1) #:: fibs.zip(fibs.tail).map { n => n._1 + n._2 } fibs take 5 foreach println } // prints // // 0 // 1 // 1 // 2 // 3
A LazyList
, like the one in the example above, may be infinite in length.
Aggregate methods, such as count
, sum
, max
or min
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 the fibs
value above and take some
more values:
import scala.math.BigInt object Main extends App { val fibs: LazyList[BigInt] = BigInt(0) #:: BigInt(1) #:: fibs.zip( fibs.tail).map(n => { println("Adding %d and %d".format(n._1, n._2)) n._1 + n._2 }) fibs take 5 foreach println fibs take 6 foreach println } // prints // // 0 // 1 // Adding 0 and 1 // 1 // Adding 1 and 1 // 2 // Adding 1 and 2 // 3 // And then prints // // 0 // 1 // 1 // 2 // 3 // Adding 2 and 3 // 5
There are a number of subtle points to the above example.
- The definition of
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. - While the
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. - One must be cautious of memoization; you can very quickly eat up large
amounts of memory if you're not careful. The reason for this is that the
memoization of the
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. - Note that some operations, including drop, dropWhile,
flatMap or collect may process a large number of intermediate
elements before returning. These necessarily hold onto the head, since
they are methods on
LazyList
, and a lazy list holds its own head. For computations of this sort where memoization is not desired, useIterator
when possible.
// For example, let's build the natural numbers and do some silly iteration // over them. // We'll start with a silly iteration def loop(s: String, i: Int, iter: Iterator[Int]): Unit = { // Stop after 200,000 if (i < 200001) { if (i % 50000 == 0) println(s + i) loop(s, iter.next(), iter) } } // Our first LazyList definition will be a val definition val lazylist1: LazyList[Int] = { def loop(v: Int): LazyList[Int] = v #:: loop(v + 1) loop(0) } // Because lazylist1 is a val, everything that the iterator produces is held // by virtue of the fact that the head of the LazyList is held in lazylist1 val it1 = lazylist1.toIterator loop("Iterator1: ", it1.next(), it1) // We can redefine this LazyList such that all we have is the Iterator left // and allow the LazyList to be garbage collected as required. Using a def // to provide the LazyList ensures that no val is holding onto the head as // is the case with lazylist1 def lazylist2: LazyList[Int] = { def loop(v: Int): LazyList[Int] = v #:: loop(v + 1) loop(0) } val it2 = lazylist2.toIterator loop("Iterator2: ", it2.next(), it2) // And, of course, we don't actually need a LazyList at all for such a simple // problem. There's no reason to use a LazyList if you don't actually need // one. val it3 = new Iterator[Int] { var i = -1 def hasNext = true def next(): Int = { i += 1; i } } loop("Iterator3: ", it3.next(), it3)
- The fact that
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 first time we try to access the tail we're going to need more // information which will require us to recurse, which will require us to // recurse, which... lazy val sov: LazyList[Vector[Int]] = Vector(0) #:: sov.zip(sov.tail).map { n => n._1 ++ n._2 }
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:
lazy val fib: LazyList[Int] = { def loop(h: Int, n: Int): LazyList[Int] = h #:: loop(n, h + n) loop(1, 1) }
- A
the type of the elements contained in this lazy list.
- Annotations
- @SerialVersionUID()
- See also
"Scala's Collection Library overview" section on
LazyLists
for more information.
- Alphabetic
- By Inheritance
- LazyList
- Serializable
- Serializable
- LinearSeqOptimized
- LinearSeq
- LinearSeq
- LinearSeqLike
- Seq
- Iterable
- Traversable
- Immutable
- AbstractSeq
- Seq
- SeqLike
- GenSeq
- GenSeqLike
- PartialFunction
- Function1
- AbstractIterable
- Iterable
- IterableLike
- Equals
- GenIterable
- GenIterableLike
- AbstractTraversable
- Traversable
- GenTraversable
- GenericTraversableTemplate
- TraversableLike
- GenTraversableLike
- Parallelizable
- TraversableOnce
- GenTraversableOnce
- FilterMonadic
- HasNewBuilder
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
def
++[B >: A, That](suffix: GenTraversableOnce[B])(implicit bf: CanBuildFrom[LazyList[A], B, That]): That
<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.- Definition Classes
- LazyList → TraversableLike → GenTraversableLike
-
def
++:[B >: A, That](prefix: scala.Traversable[B])(implicit bf: CanBuildFrom[LazyList[A], B, That]): That
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
- Definition Classes
- LazyList → TraversableLike
-
def
++:[B >: A, That](prefix: scala.TraversableOnce[B])(implicit bf: CanBuildFrom[LazyList[A], B, That]): That
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
- Definition Classes
- LazyList → TraversableLike
-
def
+:[B >: A, That](elem: B)(implicit bf: CanBuildFrom[LazyList[A], B, That]): That
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
- Definition Classes
- LazyList → SeqLike → GenSeqLike
-
def
:+[B >: A, That](elem: B)(implicit bf: CanBuildFrom[LazyList[A], B, That]): That
<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.- Definition Classes
- LazyList → SeqLike → GenSeqLike
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
addString(sb: mutable.StringBuilder, start: String, sep: String, end: String): mutable.StringBuilder
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 stringend
. Inside, the string representations (w.r.t. the methodtoString
) of all elements of this lazy list are separated by the stringsep
.An undefined state is represented with
"<not computed>"
and cycles are represented with"<cycle>"
.This method evaluates all elements of the collection.
- sb
the string builder to which elements are appended.
- start
the starting string.
- sep
the separator string.
- end
the ending string.
- returns
the string builder
b
to which elements were appended.
- Definition Classes
- LazyList → TraversableOnce
-
def
addString(b: StringBuilder): StringBuilder
- Definition Classes
- TraversableOnce
-
def
addString(b: StringBuilder, sep: String): StringBuilder
- Definition Classes
- TraversableOnce
-
def
aggregate[B](z: ⇒ B)(seqop: (B, A) ⇒ B, combop: (B, B) ⇒ B): B
- Definition Classes
- TraversableOnce → GenTraversableOnce
-
def
andThen[C](k: (A) ⇒ C): PartialFunction[Int, C]
- Definition Classes
- PartialFunction → Function1
-
def
apply(n: Int): A
- Definition Classes
- LinearSeqOptimized → SeqLike → GenSeqLike
-
def
applyOrElse[A1 <: Int, B1 >: A](x: A1, default: (A1) ⇒ B1): B1
- Definition Classes
- PartialFunction
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
canEqual(that: Any): Boolean
- Definition Classes
- IterableLike → Equals
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
def
collect[B, That](pf: PartialFunction[A, B])(implicit bf: CanBuildFrom[LazyList[A], B, That]): That
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
- Definition Classes
- LazyList → TraversableLike → GenTraversableLike
-
def
collectFirst[B](pf: PartialFunction[A, B]): Option[B]
<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.
- Definition Classes
- LazyList → TraversableOnce
- Annotations
- @tailrec()
-
def
combinations(n: Int): Iterator[LazyList[A]]
- Definition Classes
- SeqLike
-
def
companion: GenericCompanion[LazyList]
- Definition Classes
- LazyList → LinearSeq → LinearSeq → Seq → Iterable → Traversable → Seq → GenSeq → Iterable → GenIterable → Traversable → GenTraversable → GenericTraversableTemplate
-
def
compose[A](g: (A) ⇒ Int): (A) ⇒ A
- Definition Classes
- Function1
- Annotations
- @unspecialized()
-
def
contains[A1 >: A](elem: A1): Boolean
- Definition Classes
- LinearSeqOptimized → SeqLike
-
def
containsSlice[B](that: GenSeq[B]): Boolean
- Definition Classes
- SeqLike
-
def
copyToArray[B >: A](xs: Array[B], start: Int, len: Int): Unit
- Definition Classes
- IterableLike → TraversableLike → TraversableOnce → GenTraversableOnce
-
def
copyToArray[B >: A](xs: Array[B]): Unit
- Definition Classes
- TraversableOnce → GenTraversableOnce
-
def
copyToArray[B >: A](xs: Array[B], start: Int): Unit
- Definition Classes
- TraversableOnce → GenTraversableOnce
-
def
copyToBuffer[B >: A](dest: Buffer[B]): Unit
- Definition Classes
- TraversableOnce
-
final
def
corresponds[B](that: GenSeq[B])(p: (A, B) ⇒ Boolean): Boolean
- Definition Classes
- LinearSeqLike → SeqLike → GenSeqLike
- Annotations
- @tailrec()
-
def
count(p: (A) ⇒ Boolean): Int
- Definition Classes
- TraversableOnce → GenTraversableOnce
-
def
diff[B >: A](that: GenSeq[B]): LazyList[A]
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
- Definition Classes
- LazyList → SeqLike → GenSeqLike
-
def
distinct: LazyList[A]
- Definition Classes
- LazyList → SeqLike → GenSeqLike
- def distinctBy[B](f: (A) ⇒ B): LazyList[A]
-
def
drop(n: Int): LazyList[A]
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method does not evaluate anything until an operation is performed on the result (e.g. calling
head
ortail
, or checking if it is empty). Additionally, it preserves laziness for all except the firstn
elements.- Definition Classes
- LazyList → LinearSeqOptimized → IterableLike → TraversableLike → GenTraversableLike
-
def
dropRight(n: Int): LazyList[A]
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method does not evaluate anything until an operation is performed on the result (e.g. calling
head
ortail
, or checking if it is empty).- Definition Classes
- LazyList → LinearSeqOptimized → IterableLike
-
def
dropWhile(p: (A) ⇒ Boolean): LazyList[A]
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method does not evaluate anything until an operation is performed on the result (e.g. calling
head
ortail
, or checking if it is empty). Additionally, it preserves laziness for all elements after the predicate returnsfalse
.- Definition Classes
- LazyList → TraversableLike → GenTraversableLike
-
def
endsWith[B](that: GenSeq[B]): Boolean
- Definition Classes
- SeqLike → GenSeqLike
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(that: Any): Boolean
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method evaluates all elements of the collection.
- Definition Classes
- LazyList → GenSeqLike → Equals → AnyRef → Any
-
def
exists(p: (A) ⇒ Boolean): Boolean
- Definition Classes
- LinearSeqOptimized → IterableLike → TraversableLike → TraversableOnce → GenTraversableOnce
-
def
filter(pred: (A) ⇒ Boolean): LazyList[A]
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
- Definition Classes
- LazyList → TraversableLike → GenTraversableLike
-
def
filterNot(pred: (A) ⇒ Boolean): LazyList[A]
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
- Definition Classes
- LazyList → TraversableLike → GenTraversableLike
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
find(p: (A) ⇒ Boolean): Option[A]
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method does not evaluate any elements further than the first element matching the predicate.
- Definition Classes
- LazyList → LinearSeqOptimized → IterableLike → TraversableLike → TraversableOnce → GenTraversableOnce
- Annotations
- @tailrec()
-
def
flatMap[B, That](f: (A) ⇒ GenTraversableOnce[B])(implicit bf: CanBuildFrom[LazyList[A], B, That]): That
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
- Definition Classes
- LazyList → TraversableLike → GenTraversableLike → FilterMonadic
-
def
flatten[B](implicit asIterable: (A) ⇒ GenTraversableOnce[B]): LazyList[B]
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
- Definition Classes
- LazyList → GenericTraversableTemplate
-
def
fold[A1 >: A](z: A1)(op: (A1, A1) ⇒ A1): A1
- Definition Classes
- TraversableOnce → GenTraversableOnce
-
def
foldLeft[B](z: B)(op: (B, A) ⇒ B): B
LazyList specialization of foldLeft which allows GC to collect along the way.
LazyList specialization of foldLeft which allows GC to collect along the way.
- B
The type of value being accumulated.
- z
The initial value seeded into the function
op
.- op
The operation to perform on successive elements of the
LazyList
.- returns
The accumulated value from successive applications of
op
.
- Definition Classes
- LazyList → LinearSeqOptimized → TraversableOnce → GenTraversableOnce
- Annotations
- @tailrec()
-
def
foldRight[B](z: B)(op: (A, B) ⇒ B): B
- Definition Classes
- LinearSeqOptimized → IterableLike → TraversableOnce → GenTraversableOnce
-
def
forall(p: (A) ⇒ Boolean): Boolean
- Definition Classes
- LinearSeqOptimized → IterableLike → TraversableLike → TraversableOnce → GenTraversableOnce
-
def
force: LazyList.this.type
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.
- returns
this
-
def
foreach[U](f: (A) ⇒ U): Unit
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).- f
The treatment to apply to each element.
- Definition Classes
- LazyList → LinearSeqOptimized → IterableLike → GenericTraversableTemplate → TraversableLike → GenTraversableLike → TraversableOnce → GenTraversableOnce → FilterMonadic
- Annotations
- @tailrec()
- Note
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.
,This function will force the realization of the entire LazyList unless the
f
throws an exception.
-
def
genericBuilder[B]: Builder[B, LazyList[B]]
- Definition Classes
- GenericTraversableTemplate
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
groupBy[K](f: (A) ⇒ K): immutable.Map[K, LazyList[A]]
- Definition Classes
- TraversableLike → GenTraversableLike
-
def
grouped(size: Int): scala.Iterator[LazyList[A]]
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
The iterator returned by this method mostly preserves laziness; a single element ahead of the iterator is evaluated.
- Definition Classes
- LazyList → IterableLike
-
def
hasDefiniteSize: Boolean
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
- Definition Classes
- LazyList → TraversableLike → TraversableOnce → GenTraversableOnce
-
def
hashCode(): Int
- Definition Classes
- LinearSeqLike → GenSeqLike → AnyRef → Any
-
def
head: A
- Definition Classes
- LazyList → LinearSeqOptimized → IterableLike → GenericTraversableTemplate → TraversableLike → GenTraversableLike
-
def
headOption: Option[A]
- Definition Classes
- TraversableLike → GenTraversableLike
-
def
indexOf[B >: A](elem: B, from: Int): Int
- Definition Classes
- GenSeqLike
-
def
indexOf[B >: A](elem: B): Int
- Definition Classes
- GenSeqLike
-
def
indexOfSlice[B >: A](that: GenSeq[B], from: Int): Int
- Definition Classes
- SeqLike
-
def
indexOfSlice[B >: A](that: GenSeq[B]): Int
- Definition Classes
- SeqLike
-
def
indexWhere(p: (A) ⇒ Boolean, from: Int): Int
- Definition Classes
- LinearSeqOptimized → SeqLike → GenSeqLike
-
def
indexWhere(p: (A) ⇒ Boolean): Int
- Definition Classes
- GenSeqLike
-
def
indices: immutable.Range
- Definition Classes
- SeqLike
-
def
init: LazyList[A]
- Definition Classes
- LazyList → TraversableLike → GenTraversableLike
-
def
inits: Iterator[LazyList[A]]
- Definition Classes
- TraversableLike
-
def
intersect[B >: A](that: GenSeq[B]): LazyList[A]
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
- Definition Classes
- LazyList → SeqLike → GenSeqLike
-
def
isDefinedAt(x: Int): Boolean
- Definition Classes
- LinearSeqOptimized → GenSeqLike
-
def
isEmpty: Boolean
- Definition Classes
- LazyList → LinearSeqOptimized → SeqLike → IterableLike → GenericTraversableTemplate → TraversableLike → TraversableOnce → GenTraversableOnce
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
isTraversableAgain: Boolean
- Definition Classes
- TraversableLike → GenTraversableLike → GenTraversableOnce
-
def
iterator: scala.Iterator[A]
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
The iterator returned by this method preserves laziness; elements are only evaluated individually as needed.
- Definition Classes
- LazyList → LinearSeqLike → IterableLike → GenIterableLike
-
def
knownSize: Int
This method preserves laziness; elements are only evaluated individually as needed.
-
def
last: A
- Definition Classes
- LinearSeqOptimized → TraversableLike → GenTraversableLike
-
def
lastIndexOf[B >: A](elem: B, end: Int): Int
- Definition Classes
- GenSeqLike
-
def
lastIndexOf[B >: A](elem: B): Int
- Definition Classes
- GenSeqLike
-
def
lastIndexOfSlice[B >: A](that: GenSeq[B], end: Int): Int
- Definition Classes
- SeqLike
-
def
lastIndexOfSlice[B >: A](that: GenSeq[B]): Int
- Definition Classes
- SeqLike
-
def
lastIndexWhere(p: (A) ⇒ Boolean, end: Int): Int
- Definition Classes
- LinearSeqOptimized → SeqLike → GenSeqLike
-
def
lastIndexWhere(p: (A) ⇒ Boolean): Int
- Definition Classes
- GenSeqLike
-
def
lastOption: Option[A]
- Definition Classes
- TraversableLike → GenTraversableLike
-
def
lazyAppendedAll[B >: A](suffix: ⇒ GenTraversableOnce[B]): LazyList[B]
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.- suffix
The collection that gets appended to this lazy list
- returns
The lazy list containing elements of this lazy list and the iterable object.
-
def
length: Int
- Definition Classes
- LinearSeqOptimized → SeqLike → GenSeqLike
-
def
lengthCompare(len: Int): Int
- Definition Classes
- LinearSeqOptimized → SeqLike
-
def
lift: (Int) ⇒ Option[A]
- Definition Classes
- PartialFunction
-
def
map[B, That](f: (A) ⇒ B)(implicit bf: CanBuildFrom[LazyList[A], B, That]): That
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
- Definition Classes
- LazyList → TraversableLike → GenTraversableLike → FilterMonadic
-
def
max[B >: A](implicit cmp: Ordering[B]): A
- Definition Classes
- TraversableOnce → GenTraversableOnce
-
def
maxBy[B](f: (A) ⇒ B)(implicit cmp: Ordering[B]): A
- Definition Classes
- TraversableOnce → GenTraversableOnce
-
def
min[B >: A](implicit cmp: Ordering[B]): A
- Definition Classes
- TraversableOnce → GenTraversableOnce
-
def
minBy[B](f: (A) ⇒ B)(implicit cmp: Ordering[B]): A
- Definition Classes
- TraversableOnce → GenTraversableOnce
-
def
mkString: String
- Definition Classes
- TraversableOnce → GenTraversableOnce
-
def
mkString(sep: String): String
- Definition Classes
- TraversableOnce → GenTraversableOnce
-
def
mkString(start: String, sep: String, end: String): String
- Definition Classes
- TraversableOnce → GenTraversableOnce
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
newBuilder: Builder[A, LazyList[A]]
- Attributes
- protected[this]
- Definition Classes
- GenericTraversableTemplate → HasNewBuilder
-
def
nonEmpty: Boolean
- Definition Classes
- TraversableOnce → GenTraversableOnce
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
orElse[A1 <: Int, B1 >: A](that: PartialFunction[A1, B1]): PartialFunction[A1, B1]
- Definition Classes
- PartialFunction
-
def
padTo[B >: A, That](len: Int, elem: B)(implicit bf: CanBuildFrom[LazyList[A], B, That]): That
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
- Definition Classes
- LazyList → SeqLike → GenSeqLike
-
def
par: ParSeq[A]
- Definition Classes
- Parallelizable
-
def
parCombiner: Combiner[A, ParSeq[A]]
- Attributes
- protected[this]
- Definition Classes
- Seq → SeqLike → Iterable → TraversableLike → Parallelizable
-
def
partition(p: (A) ⇒ Boolean): (LazyList[A], LazyList[A])
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
- Definition Classes
- LazyList → TraversableLike → GenTraversableLike
-
def
partitionMap[A1, A2](f: (A) ⇒ Either[A1, A2]): (LazyList[A1], LazyList[A2])
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
-
def
patch[B >: A, That](from: Int, other: GenSeq[B], replaced: Int)(implicit bf: CanBuildFrom[LazyList[A], B, That]): That
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
- Definition Classes
- LazyList → SeqLike → GenSeqLike
-
def
permutations: Iterator[LazyList[A]]
- Definition Classes
- SeqLike
-
def
prefixLength(p: (A) ⇒ Boolean): Int
- Definition Classes
- GenSeqLike
-
def
product[B >: A](implicit num: Numeric[B]): B
- Definition Classes
- TraversableOnce → GenTraversableOnce
-
def
reduce[A1 >: A](op: (A1, A1) ⇒ A1): A1
- Definition Classes
- TraversableOnce → GenTraversableOnce
-
def
reduceLeft[B >: A](f: (B, A) ⇒ B): B
LazyList specialization of reduceLeft which allows GC to collect along the way.
LazyList specialization of reduceLeft which allows GC to collect along the way.
- B
The type of value being accumulated.
- f
The operation to perform on successive elements of the
LazyList
.- returns
The accumulated value from successive applications of
f
.
- Definition Classes
- LazyList → LinearSeqOptimized → TraversableOnce
-
def
reduceLeftOption[B >: A](op: (B, A) ⇒ B): Option[B]
- Definition Classes
- TraversableOnce → GenTraversableOnce
-
def
reduceOption[A1 >: A](op: (A1, A1) ⇒ A1): Option[A1]
- Definition Classes
- TraversableOnce → GenTraversableOnce
-
def
reduceRight[B >: A](op: (A, B) ⇒ B): B
- Definition Classes
- LinearSeqOptimized → IterableLike → TraversableOnce → GenTraversableOnce
-
def
reduceRightOption[B >: A](op: (A, B) ⇒ B): Option[B]
- Definition Classes
- TraversableOnce → GenTraversableOnce
-
def
repr: LazyList[A]
- Definition Classes
- TraversableLike → GenTraversableLike
-
def
reverse: LazyList[A]
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method evaluates all elements of the collection.
- Definition Classes
- LazyList → SeqLike → GenSeqLike
-
def
reverseIterator: Iterator[A]
- Definition Classes
- SeqLike
-
def
reverseMap[B, That](f: (A) ⇒ B)(implicit bf: CanBuildFrom[LazyList[A], B, That]): That
- Definition Classes
- SeqLike → GenSeqLike
-
def
reversed: List[A]
- Attributes
- protected[this]
- Definition Classes
- TraversableOnce
-
def
runWith[U](action: (A) ⇒ U): (Int) ⇒ Boolean
- Definition Classes
- PartialFunction
-
def
sameElements[B >: A](that: GenIterable[B]): Boolean
- Definition Classes
- LazyList → LinearSeqOptimized → IterableLike → GenIterableLike
-
def
scan[B >: A, That](z: B)(op: (B, B) ⇒ B)(implicit cbf: CanBuildFrom[LazyList[A], B, That]): That
- Definition Classes
- TraversableLike → GenTraversableLike
-
def
scanLeft[B, That](z: B)(op: (B, A) ⇒ B)(implicit bf: CanBuildFrom[LazyList[A], B, That]): That
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
- Definition Classes
- LazyList → TraversableLike → GenTraversableLike
-
def
scanRight[B, That](z: B)(op: (A, B) ⇒ B)(implicit bf: CanBuildFrom[LazyList[A], B, That]): That
- Definition Classes
- TraversableLike → GenTraversableLike
- Annotations
- @migration
- Migration
(Changed in version 2.9.0) The behavior of
scanRight
has changed. The previous behavior can be reproduced with scanRight.reverse.
-
def
segmentLength(p: (A) ⇒ Boolean, from: Int): Int
- Definition Classes
- LinearSeqOptimized → SeqLike → GenSeqLike
-
def
seq: immutable.LinearSeq[A]
- Definition Classes
- LinearSeq → LinearSeq → LinearSeqLike → Seq → Seq → GenSeq → GenSeqLike → Iterable → Iterable → GenIterable → Traversable → Traversable → GenTraversable → Parallelizable → TraversableOnce → GenTraversableOnce
-
def
size: Int
- Definition Classes
- SeqLike → GenTraversableLike → TraversableOnce → GenTraversableOnce
-
def
sizeHintIfCheap: Int
- Attributes
- protected[collection]
- Definition Classes
- GenTraversableOnce
-
def
slice(from: Int, until: Int): LazyList[A]
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method does not evaluate anything until an operation is performed on the result (e.g. calling
head
ortail
, or checking if it is empty). Additionally, it preserves laziness for all but the firstfrom
elements.- Definition Classes
- LazyList → LinearSeqOptimized → IterableLike → TraversableLike → GenTraversableLike
-
def
sliding(size: Int, step: Int): scala.Iterator[LazyList[A]]
<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.- Definition Classes
- LazyList → IterableLike
-
def
sliding(size: Int): Iterator[LazyList[A]]
- Definition Classes
- IterableLike
-
def
sortBy[B](f: (A) ⇒ B)(implicit ord: math.Ordering[B]): LazyList[A]
- Definition Classes
- SeqLike
-
def
sortWith(lt: (A, A) ⇒ Boolean): LazyList[A]
- Definition Classes
- SeqLike
-
def
sorted[B >: A](implicit ord: math.Ordering[B]): LazyList[A]
- Definition Classes
- SeqLike
-
def
span(p: (A) ⇒ Boolean): (LazyList[A], LazyList[A])
- Definition Classes
- LazyList → LinearSeqOptimized → TraversableLike → GenTraversableLike
-
def
splitAt(n: Int): (LazyList[A], LazyList[A])
- Definition Classes
- LazyList → TraversableLike → GenTraversableLike
-
def
startsWith[B](that: GenSeq[B], offset: Int): Boolean
- Definition Classes
- SeqLike → GenSeqLike
-
def
startsWith[B](that: GenSeq[B]): Boolean
- Definition Classes
- GenSeqLike
-
def
stringPrefix: String
- Definition Classes
- LazyList → TraversableLike → GenTraversableLike
-
def
sum[B >: A](implicit num: Numeric[B]): B
- Definition Classes
- TraversableOnce → GenTraversableOnce
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
tail: LazyList[A]
- Definition Classes
- LazyList → LinearSeqOptimized → TraversableLike → GenTraversableLike
-
def
tails: Iterator[LazyList[A]]
- Definition Classes
- LinearSeqOptimized → TraversableLike
-
def
take(n: Int): LazyList[A]
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
- Definition Classes
- LazyList → LinearSeqOptimized → IterableLike → TraversableLike → GenTraversableLike
-
def
takeRight(n: Int): LazyList[A]
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method does not evaluate anything until an operation is performed on the result (e.g. calling
head
ortail
, or checking if it is empty).- Definition Classes
- LazyList → IterableLike
-
def
takeWhile(p: (A) ⇒ Boolean): LazyList[A]
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
- Definition Classes
- LazyList → LinearSeqOptimized → IterableLike → TraversableLike → GenTraversableLike
-
def
tapEach[U](f: (A) ⇒ U): LazyList[A]
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
-
def
thisCollection: LinearSeq[A]
- Attributes
- protected[this]
- Definition Classes
- LinearSeqLike → SeqLike → IterableLike → TraversableLike
-
def
to[Col[_]](implicit cbf: CanBuildFrom[Nothing, A, Col[A]]): Col[A]
- Definition Classes
- LazyList → TraversableLike → TraversableOnce → GenTraversableOnce
-
def
toArray[B >: A](implicit arg0: ClassTag[B]): Array[B]
- Definition Classes
- TraversableOnce → GenTraversableOnce
-
def
toBuffer[B >: A]: Buffer[B]
- Definition Classes
- TraversableOnce → GenTraversableOnce
-
def
toCollection(repr: LazyList[A]): LinearSeq[A]
- Attributes
- protected[this]
- Definition Classes
- LinearSeqLike → SeqLike → IterableLike → TraversableLike
-
def
toIndexedSeq: immutable.IndexedSeq[A]
- Definition Classes
- TraversableOnce → GenTraversableOnce
-
def
toIterable: Iterable[A]
- Definition Classes
- IterableLike → TraversableOnce → GenTraversableOnce
-
def
toIterator: Iterator[A]
- Definition Classes
- IterableLike → TraversableLike → GenTraversableOnce
- Annotations
- @deprecatedOverriding( ... , "2.11.0" )
-
def
toList: List[A]
- Definition Classes
- TraversableOnce → GenTraversableOnce
-
def
toMap[T, U](implicit ev: <:<[A, (T, U)]): immutable.Map[T, U]
- Definition Classes
- TraversableOnce → GenTraversableOnce
-
def
toSeq: immutable.Seq[A]
- Definition Classes
- Seq → SeqLike → GenSeqLike → TraversableOnce → GenTraversableOnce
-
def
toSet[B >: A]: immutable.Set[B]
- Definition Classes
- TraversableOnce → GenTraversableOnce
-
def
toStream: immutable.Stream[A]
- Definition Classes
- IterableLike → TraversableLike → GenTraversableOnce
-
def
toString(): String
This method preserves laziness; elements are only evaluated individually as needed.
This method preserves laziness; elements are only evaluated individually as needed.
- returns
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.
- Definition Classes
- LazyList → SeqLike → Function1 → TraversableLike → AnyRef → Any
-
def
toTraversable: Traversable[A]
- Definition Classes
- TraversableLike → TraversableOnce → GenTraversableOnce
- Annotations
- @deprecatedOverriding( ... , "2.11.0" )
-
def
toVector: Vector[A]
- Definition Classes
- TraversableOnce → GenTraversableOnce
-
def
transpose[B](implicit asTraversable: (A) ⇒ GenTraversableOnce[B]): LazyList[LazyList[B]]
- Definition Classes
- GenericTraversableTemplate
- Annotations
- @migration
- Migration
(Changed in version 2.9.0)
transpose
throws anIllegalArgumentException
if collections are not uniformly sized.
-
def
union[B >: A, That](that: GenSeq[B])(implicit bf: CanBuildFrom[LazyList[A], B, That]): That
- Definition Classes
- SeqLike → GenSeqLike
-
def
unzip[A1, A2](implicit asPair: (A) ⇒ (A1, A2)): (LazyList[A1], LazyList[A2])
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
- Definition Classes
- LazyList → GenericTraversableTemplate
-
def
unzip3[A1, A2, A3](implicit asTriple: (A) ⇒ (A1, A2, A3)): (LazyList[A1], LazyList[A2], LazyList[A3])
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
- Definition Classes
- LazyList → GenericTraversableTemplate
-
def
updated[B >: A, That](index: Int, elem: B)(implicit bf: CanBuildFrom[LazyList[A], B, That]): That
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
- Definition Classes
- LazyList → SeqLike → GenSeqLike
-
def
view(from: Int, until: Int): SeqView[A, LazyList[A]]
- Definition Classes
- SeqLike → IterableLike → TraversableLike
-
def
view: SeqView[A, LazyList[A]]
- Definition Classes
- SeqLike → IterableLike → TraversableLike
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
def
withFilter(p: (A) ⇒ Boolean): FilterMonadic[A, LazyList[A]]
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.- Definition Classes
- LazyList → TraversableLike → FilterMonadic
-
def
writeReplace(): AnyRef
- Attributes
- protected[this]
-
def
zip[A1 >: A, B, That](that: GenIterable[B])(implicit bf: CanBuildFrom[LazyList[A], (A1, B), That]): That
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
- Definition Classes
- LazyList → IterableLike → GenIterableLike
-
def
zipAll[B, A1 >: A, That](that: GenIterable[B], thisElem: A1, thatElem: B)(implicit bf: CanBuildFrom[LazyList[A], (A1, B), That]): That
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
- Definition Classes
- LazyList → IterableLike → GenIterableLike
-
def
zipWithIndex[A1 >: A, That](implicit bf: CanBuildFrom[LazyList[A], (A1, Int), That]): That
<invalid inheritdoc annotation>
<invalid inheritdoc annotation>
This method preserves laziness; elements are only evaluated individually as needed.
- Definition Classes
- LazyList → IterableLike → GenIterableLike
Deprecated Value Members
-
def
/:[B](z: B)(op: (B, A) ⇒ B): B
- Definition Classes
- TraversableOnce → GenTraversableOnce
- Annotations
- @deprecated
- Deprecated
(Since version 2.12.10) Use foldLeft instead of /:
-
def
:\[B](z: B)(op: (A, B) ⇒ B): B
- Definition Classes
- TraversableOnce → GenTraversableOnce
- Annotations
- @deprecated
- Deprecated
(Since version 2.12.10) Use foldRight instead of :\