scala.collection.immutable

object Stream

[source: scala/collection/immutable/Stream.scala]

object Stream
extends SeqFactory[Stream]
The object Stream provides helper functions to manipulate streams.
Author
Martin Odersky, Matthias Zenger
Version
1.1 08/08/03
Since
2.8
Value Summary
lazy val lazy_:: : #::
Method Summary
override def apply [A](xs : A*) : Stream[A]
A stream consisting of given elements
implicit def canBuildFrom [A] : CanBuildFrom[Stream, A, Stream[A]]
def concat [A](xs : Iterator[Stream[A]]) : Stream[A]
The concatenation of all streams returned by an iterator
def concat [A](xs : Iterable[Stream[A]]) : Stream[A]
The concatenation of a sequence of streams
implicit def consWrapper [A](stream : => Stream[A]) : ConsWrapper[A]
A wrapper method that adds `#::` for cons and `#::: for concat as operations to streams.
def const [A](elem : A) : Stream[A]
Create an infinite stream containing the given element.
def continually [A](elem : => A) : Stream[A]
Create an infinite stream containing the given element expression (which is computed for each occurrence)
override def empty [A] : Stream[A]
The empty stream
override def fill [A](n : Int)(elem : => A) : Stream[A]
A traversable that contains the results of some element computation a number of times.
def from (start : Int) : Stream[Int]
Create an infinite stream starting at start and incrementing by 1.
def from (start : Int, step : Int) : Stream[Int]
Create an infinite stream starting at start and incrementing by step step
def fromIterator [A](it : Iterator[A]) : Stream[A]
A stream containing all elements of a given iterator, in the order they are produced.
def iterate [A](start : A)(f : (A) => A) : Stream[A]
An infinite stream that repeatedly applies a given function to a start value.
override def iterate [A](start : A, len : Int)(f : (A) => A) : Stream[A]
A traversable containing repeated applications of a function to a start value.
def make [A](n : Int, elem : A) : Stream[A]
Create a stream containing several copies of an element.
def newBuilder [A] : Builder[A, Stream[A]]
Creates a new builder for a stream
def range (start : Int, end : Int, step : (Int) => Int) : Stream[Int]
Create a stream with element values vn+1 = step(vn) where v0 = start and elements are in the range between start (inclusive) and end (exclusive)
override def range (start : Int, end : Int, step : Int) : Stream[Int]
A traversable containing equally spaced values in some integer interval.
override def tabulate [A](n : Int)(f : (Int) => A) : Stream[A]
A traversable containing values of a given function over a range of integer values starting from 0.
Methods inherited from SeqFactory
unapplySeq
Methods inherited from TraversableFactory
concat, fill, fill, fill, fill, tabulate, tabulate, tabulate, tabulate, range
Methods inherited from AnyRef
getClass, hashCode, equals, clone, toString, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Class Summary
final class Cons [+A](hd : A, tl : => Stream[A]) extends Stream[A]
A lazy cons cell, from which streams are built.
class ConsWrapper [A](tl : => Stream[A]) extends AnyRef
A wrapper class that adds `#::` for cons and `#:::` for concat as operations to streams.
class StreamBuilder [A] extends LazyBuilder[A, Stream[A]]
A builder for streams
class StreamCanBuildFrom [A] extends GenericCanBuildFrom[A]
The factory for streams.
Object Summary
object #:: extends AnyRef
An extractor that allows to pattern match streams with `#::`.
object Empty extends Stream[Nothing]
object cons extends AnyRef
An alternative way of building and matching Streams using Stream.cons(hd, tl).
Value Details
lazy val lazy_:: : #::

Method Details
implicit def canBuildFrom[A] : CanBuildFrom[Stream, A, Stream[A]]

def newBuilder[A] : Builder[A, Stream[A]]
Creates a new builder for a stream

override def empty[A] : Stream[A]
The empty stream

override def apply[A](xs : A*) : Stream[A]
A stream consisting of given elements

implicit def consWrapper[A](stream : => Stream[A]) : ConsWrapper[A]
A wrapper method that adds `#::` for cons and `#::: for concat as operations to streams.

def iterate[A](start : A)(f : (A) => A) : Stream[A]
An infinite stream that repeatedly applies a given function to a start value.
Parameters
start - the start value of the stream
f - the function that's repeatedly applied
Returns
the stream returning the infinite sequence of values `start, f(start), f(f(start)), ...`

override def iterate[A](start : A, len : Int)(f : (A) => A) : Stream[A]
A traversable containing repeated applications of a function to a start value.
Parameters
start - the start value of the traversable
len - the number of elements returned by the traversable
f - the function that's repeatedly applied
Returns
the traversable returning `len` values in the sequence `start, f(start), f(f(start)), ...`

def from(start : Int, step : Int) : Stream[Int]
Create an infinite stream starting at start and incrementing by step step
Parameters
start - the start value of the stream
step - the increment value of the stream
Returns
the stream starting at value start.

def from(start : Int) : Stream[Int]
Create an infinite stream starting at start and incrementing by 1.
Parameters
start - the start value of the stream
Returns
the stream starting at value start.

def continually[A](elem : => A) : Stream[A]
Create an infinite stream containing the given element expression (which is computed for each occurrence)
Parameters
elem - the element composing the resulting stream
Returns
the stream containing an infinite number of elem

override def fill[A](n : Int)(elem : => A) : Stream[A]
A traversable that contains the results of some element computation a number of times.
Parameters
n - the number of elements returned
elem - the element computation

override def tabulate[A](n : Int)(f : (Int) => A) : Stream[A]
A traversable containing values of a given function over a range of integer values starting from 0.
Parameters
n - The number of elements in the traversable
f - The function computing element values
Returns
A traversable consisting of elements `f(0), ..., f(n -1)`

override def range(start : Int, end : Int, step : Int) : Stream[Int]
A traversable containing equally spaced values in some integer interval.
Parameters
start - the start value of the traversable
end - the end value of the traversable (the first value NOT returned)
step - the increment value of the traversable (must be positive or negative)
Returns
the traversable with values in `start, start + step, ...` up to, but excluding `end`

@deprecated("use it.toStream instead")

def fromIterator[A](it : Iterator[A]) : Stream[A]
A stream containing all elements of a given iterator, in the order they are produced.
Parameters
it - The iterator producing the stream's elements

@deprecated("use xs.flatten instead")

def concat[A](xs : Iterable[Stream[A]]) : Stream[A]
The concatenation of a sequence of streams

@deprecated("use xs.toStream.flatten instead")

def concat[A](xs : Iterator[Stream[A]]) : Stream[A]
The concatenation of all streams returned by an iterator

@deprecated("use `iterate' instead.")

def range(start : Int, end : Int, step : (Int) => Int) : Stream[Int]
Create a stream with element values vn+1 = step(vn) where v0 = start and elements are in the range between start (inclusive) and end (exclusive)
Parameters
start - the start value of the stream
end - the end value of the stream
step - the increment function of the stream, must be monotonically increasing or decreasing
Returns
the stream starting at value start.

@deprecated("use `continually' instead")

def const[A](elem : A) : Stream[A]
Create an infinite stream containing the given element.
Parameters
elem - the element composing the resulting stream
Returns
the stream containing an infinite number of elem

@deprecated("use fill(n, elem) instead")

def make[A](n : Int, elem : A) : Stream[A]
Create a stream containing several copies of an element.
Parameters
n - the length of the resulting stream
elem - the element composing the resulting stream
Returns
the stream composed of n elements all equal to elem