Scala Library


scala/Stream.scala
]
abstract
class
Stream[+A]
extends
Projection[A]The class Stream
implements lazy lists where elements
are only evaluated when they are needed. Here is an example:
object Main extends Application { def from(n: Int): Stream[Int] = Stream.cons(n, from(n + 1)) def sieve(s: Stream[Int]): Stream[Int] = Stream.cons(s.head, sieve(s.tail filter { _ % s.head != 0 })) def primes = sieve(from(2)) primes take 10 print }
Method Summary  
protected abstract def

addDefinedElems
(buf : StringBuilder, prefix : java.lang.String) : StringBuilder
Write all elements of this string into given string builder

override def

append
[B >: A](rest : => Iterable[B]) : Stream[B]
The stream resulting from the concatenation of this stream with the argument stream.

override def

apply
(n : Int) : A
Returns the
n th element of this stream. The first element
(head of the stream) is at position 0. 
override final def

copyToArray
[B >: A](xs : Array[B], start : Int) : Unit
Fills the given array
xs with the elements of
this stream starting at position start . 
override final def

drop
(n : Int) : Stream[A]
Returns the stream without its
n first elements.
If the stream has less than n elements, the empty stream is returned. 
override final def

dropWhile
(p : (A) => Boolean) : Stream[A]
Returns the longest suffix of this stream whose first element
does not satisfy the predicate
p . 
override def

elements
: Iterator[A]
An iterator returning the elements of this stream one by one.

override final def

exists
(p : (A) => Boolean) : Boolean
Tests the existence in this stream of an element that satisfies the
predicate
p . 
override final def

filter
(p : (A) => Boolean) : Stream[A]
Returns all the elements of this stream that satisfy the
predicate
p . The order of the elements is preserved. 
override def

flatMap
[B](f : (A) => Iterable[B]) : Stream[B]
Applies the given function
f to each element of
this stream, then concatenates the results. 
override final def

foldLeft
[B](z : B)(f : (B, A) => B) : B
Combines the elements of this stream together using the binary
function
f , from left to right, and starting with
the value z . 
override def

foldRight
[B](z : B)(f : (A, B) => B) : B
Combines the elements of this stream together using the binary
function
f , from rigth to left, and starting with
the value z . 
override final def

forall
(p : (A) => Boolean) : Boolean
Tests if the predicate
p is satisfied by all elements
in this stream. 
override def

force
: List[A]
convert to a copied strict collection

override final def

foreach
(f : (A) => Unit) : Unit
Apply the given function
f to each element of this stream
(while respecting the order of the elements). 
override def

hasDefiniteSize
: Boolean
returns true iff this collection has a bound size.
Many APIs in this trait will not work on collections of
unbound sizes.

abstract def

head
: A
The first element of this stream

def

init
: Stream[A]
The stream without its last element.

override abstract def

isEmpty
: Boolean
is this stream empty?

override final def

last
: A
Returns the last element of this stream.

override def

length
: Int
The length of this stream

override final def

lengthCompare
(l : Int) : Int
Result of comparing
length with operand l .
returns x where
x < 0 iff this.length < l
x == 0 iff this.length == l
x > 0 iff this.length > that .
This method is used by matching streams against rightignoring (...,_*) patterns.
This method does not call Stream.length , it works for O(l) ,
not for O(length) and does not force full Stream evaluation. 
override def

map
[B](f : (A) => B) : Stream[B]
Returns the stream resulting from applying the given function
f to each
element of this stream. 
def

print
: Unit
Prints elements of this stream one by one, separated by commas

def

print
(sep : java.lang.String) : Unit
Prints elements of this stream one by one, separated by
sep 
override def

reverse
: Stream[A]
A stream consisting of all elements of this stream in reverse order.

abstract def

tail
: Stream[A]
A stream consisting of the remaining elements of this stream after the first one.

override def

take
(n : Int) : Stream[A]
Returns the
n first elements of this stream, or else the whole
stream, if it has less than n elements. 
override def

takeWhile
(p : (A) => Boolean) : Stream[A]
Returns the longest prefix of this stream whose elements satisfy
the predicate
p . 
override def

toStream
: Stream[A]
Returns a stream containing all of the elements in this iterable object.

override def

toString
: java.lang.String
Converts stream to string

def

zip
[B](that : Stream[B]) : Stream[(A, B)]
Returns a stream formed from this stream and the specified stream
that by associating each element of the former with
the element at the same position in the latter.
If one of the two streams is longer than the other, its remaining elements are ignored. 
def

zipWithIndex
: Stream[(A, Int)]
Returns a stream that pairs each element of this stream
with its index, counting from 0.

Methods inherited from Projection  
projection 
Methods inherited from Seq  
size, concat, lastOption, first, firstOption, headOption, ++, isDefinedAt, lastIndexOf, findIndexOf, indexOf, slice, slice, contains, subseq, toArray, toSeq, equalsWith, startsWith, startsWith, endsWith, indexOf, containsSlice 
Methods inherited from Collection  
stringPrefix 
Methods inherited from Iterable  
partition, find, /:, :\, reduceLeft, reduceRight, copyToBuffer, sameElements, toList, mkString, mkString, mkString, addString, addString, addString 
Methods inherited from PartialFunction  
orElse, andThen 
Methods inherited from Function1  
compose 
Methods inherited from AnyRef  
getClass, hashCode, equals, clone, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized 
Methods inherited from Any  
==, !=, isInstanceOf, asInstanceOf 
Method Details 
override abstract
def
isEmpty : Boolean
abstract
def
head : A
override
def
length : Int
length
with operand l
.
returns x
where
x < 0
iff this.length < l
x == 0
iff this.length == l
x > 0
iff this.length > that
.
This method is used by matching streams against rightignoring (...,_*) patterns.
This method does not call Stream.length
, it works for O(l)
,
not for O(length)
and does not force full Stream evaluation.override
def
hasDefiniteSize : Boolean
rest 
The stream that gets appended to this streamoverride final
def
last : A
n
th element of this stream. The first element
(head of the stream) is at position 0.n 
index of the element to returnn
in this stream.n
first elements of this stream, or else the whole
stream, if it has less than n
elements.n 
the number of elements to take.n
first elements of this stream.n
first elements.
If the stream has less than n
elements, the empty stream is returned.n 
the number of elements to drop.n
first elements.p
.p 
the test predicate.p
.p
.p 
the test predicate.p
.f
to each
element of this stream.f 
function to apply to each element.[f(a0), ..., f(an)]
if this stream is [a0, ..., an]
.f
to each element of this stream
(while respecting the order of the elements).f 
the treatment to apply to each element.p
. The order of the elements is preserved.p 
the predicate used to filter the stream.p
.p
is satisfied by all elements
in this stream.p 
the test predicate.true
iff all elements of this stream satisfy the predicate p
.p
.p 
the test predicate.true
iff there exists an element in this stream that satisfies the predicate p
.f
, from left to right, and starting with
the value z
.f(... (f(f(z, a_{0}), a_{1}) ...), a_{n})
if the stream is
[a_{0}, a_{1}, ..., a_{n}]
.f
, from rigth to left, and starting with
the value z
.f(a_{0}, f(a_{1}, f(..., f(a_{n}, z)...)))
if the stream is [a_{0}, a1, ..., a_{n}]
.f
to each element of
this stream, then concatenates the results.f 
the function to apply on each element.f(a_{0}) ::: ... ::: f(a_{n})
if this stream is [a_{0}, ..., a_{n}]
.projection
for lazy behavior.xs
with the elements of
this stream starting at position start
.xs 
the array to fill.start 
starting index.that
by associating each element of the former with
the element at the same position in the latter.
If one of the two streams is longer than the other, its remaining elements are ignored.Stream({a_{0},b_{0}}, ..., {a_{min(m,n)},b_{min(m,n)})}
when
Stream(a_{0}, ..., a_{m})
zip Stream(b_{0}, ..., b_{n})
is invoked.Stream({a_{0},0}, {a_{0},1},...)
where a_{i}
are the elements of this stream.
def
print : Unit
def
print(sep : java.lang.String) : Unit
sep
sep 
The separator string printed between consecutive elements.override
def
toString : java.lang.String
protected abstract
def
addDefinedElems(buf : StringBuilder, prefix : java.lang.String) : StringBuilder
Scala Library

