|
Scala 2.3.3
|
abstract
trait
Stream
[a]
extends
java.lang.Object
with
scala.Seq[a]
with
scala.ScalaObject
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 { x => x % s.head != 0 })) def primes = sieve(from(2)) primes take 10 print }
Def Summary | |
abstract protected
|
def
addDefinedElems
(buf: scala.compat.StringBuilder, prefix: java.lang.String)
: scala.compat.StringBuilder
Write all elements of this string into given string builder |
def
append
[b >: a]
(rest: => scala.Stream[b])
: scala.Stream[b]
The stream resulting from the concatenation of thsi stream with the argument stream. |
|
def
apply
(n: scala.Int)
: a
Returns the n -th element of this stream. The first element
(head of the stream) is at position 0.
|
|
override
|
def
copyToArray
[b >: a]
(xs: scala.Array[b], start: scala.Int)
: scala.Unit
Fills the given array xs with the elements of
this stream starting at position start .
|
override
|
def
drop
(n: scala.Int)
: scala.Stream[a]
Returns the stream without its n first elements.
If the stream has less than n elements, the empty stream is returned.
|
override
|
def
dropWhile
(p: (a) => scala.Boolean)
: scala.Stream[a]
Returns the longest suffix of this stream whose first element does not satisfy the predicate p .
|
def
elements
: scala.Iterator[a]
An iterator returning the elements of this stream one by one. |
|
override
|
def
exists
(p: (a) => scala.Boolean)
: scala.Boolean
Tests the existence in this stream of an element that satisfies the predicate p .
|
override
|
def
filter
(p: (a) => scala.Boolean)
: scala.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) => scala.Iterable[b])
: scala.Stream[b]
Applies the given function f to each element of
this stream, then concatenates the results.
|
override
|
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
|
def
forall
(p: (a) => scala.Boolean)
: scala.Boolean
Tests if the predicate p is satisfied by all elements
in this stream.
|
override
|
def
foreach
(f: (a) => scala.Unit)
: scala.Unit
Apply the given function f to each element of this stream
(while respecting the order of the elements).
|
abstract
|
def
head
: a
The first element of this stream |
def
init
: scala.Stream[a]
The stream without its last element. |
|
abstract override
|
def
isEmpty
: scala.Boolean
is this stream empty? |
def
last
: a
Returns the last element of this stream. |
|
def
length
: scala.Int
The length of this stream |
|
override
|
def
map
[b]
(f: (a) => b)
: scala.Stream[b]
Returns the stream resulting from applying the given function f to each
element of this stream.
|
def
print
(out: java.io.PrintStream)
: scala.Unit
|
|
def
print
(out: java.io.PrintStream, sep: java.lang.String)
: scala.Unit
|
|
def
print
(sep: java.lang.String)
: scala.Unit
Prints elements of this stream one by one, separated by sep
|
|
def
print
: scala.Unit
Prints elements of this stream one by one, separated by commas |
|
override
|
def
reverse
: scala.Stream[a]
A stream consisting of all elements of this stream in reverse order. |
abstract
|
def
tail
: scala.Stream[a]
A stream consisting of the remaining elements of this stream after the first one. |
override
|
def
take
(n: scala.Int)
: scala.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) => scala.Boolean)
: scala.Stream[a]
Returns the longest prefix of this stream whose elements satisfy the predicate p .
|
override
|
def
toString
: java.lang.String
Converts stream to string |
def
zip
[b]
(that: scala.Stream[b])
: scala.Stream[scala.Tuple2[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
: scala.Stream[scala.Tuple2[a, scala.Int]]
Returns a stream that pairs each element of this stream with its index, counting from 0. |
Def inherited from scala.Seq[a] | |
++ , concat, contains, copyToArray, drop, dropWhile, filter, flatMap, isDefinedAt, isEmpty, lastIndexOf, length, map, reverse, slice, stringPrefix, subseq, super$drop, super$dropWhile, super$filter, super$take, super$takeWhile, take, takeWhile, toArray, toString |
Def Detail |
abstract protected
def
addDefinedElems
(buf: scala.compat.StringBuilder, prefix: java.lang.String): scala.compat.StringBuilder
def
append
[b >: a](rest: => scala.Stream[b]): scala.Stream[b]
rest -
The stream that gets appended to this stream
n
-th element of this stream. The first element
(head of the stream) is at position 0.n -
index of the element to return
n
in this stream.
Predef.NoSuchElementException -
if the stream is too short.
override
def
copyToArray
[b >: a](xs: scala.Array[b], start: scala.Int): scala.Unit
xs
with the elements of
this stream starting at position start
.xs -
the array to fill.
start -
starting index.
override
def
drop
(n: scala.Int): scala.Stream[a]
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.
override
def
dropWhile
(p: (a) => scala.Boolean): scala.Stream[a]
p
.p -
the test predicate.
p
.
def
elements
: scala.Iterator[a]
override
def
exists
(p: (a) => scala.Boolean): scala.Boolean
p
.p -
the test predicate.
true
iff there exists an element in this stream that satisfies the predicate p
.
override
def
filter
(p: (a) => scala.Boolean): scala.Stream[a]
p
. The order of the elements is preserved.p -
the predicate used to filter the stream.
p
.
override
def
flatMap
[b](f: (a) => scala.Iterable[b]): scala.Stream[b]
f
to each element of
this stream, then concatenates the results.f -
the function to apply on each element.
f(a0) ::: ... ::: f(an)
if this stream is [a0, ..., an]
.
f
, from left to right, and starting with
the value z
.f(... (f(f(z, a0), a1) ...), an)
if the stream is
[a0, a1, ..., an]
.
f
, from rigth to left, and starting with
the value z
.f(a0, f(a1, f(..., f(an, z)...)))
if the stream is [a0, a1, ..., an]
.
override
def
forall
(p: (a) => scala.Boolean): scala.Boolean
p
is satisfied by all elements
in this stream.p -
the test predicate.
true
iff all elements of this stream satisfy the predicate p
.
override
def
foreach
(f: (a) => scala.Unit): scala.Unit
f
to each element of this stream
(while respecting the order of the elements).f -
the treatment to apply to each element.
abstract
def
head
: a
Predef.NoSuchElementException -
if the stream is empty.
def
init
: scala.Stream[a]
Predef.UnsupportedOperationException -
if the stream is empty.
abstract override
def
isEmpty
: scala.Boolean
def
last
: a
Predef.NoSuchElementException -
if the stream is empty.
def
length
: scala.Int
override
def
map
[b](f: (a) => b): scala.Stream[b]
f
to each
element of this stream.f -
function to apply to each element.
[f(a0), ..., f(an)]
if this stream is [a0, ..., an]
.
def
print
(out: java.io.PrintStream): scala.Unit
def
print
(out: java.io.PrintStream, sep: java.lang.String): scala.Unit
def
print
(sep: java.lang.String): scala.Unit
sep
sep -
The separator string printed between consecutive elements.
def
print
: scala.Unit
override
def
reverse
: scala.Stream[a]
abstract
def
tail
: scala.Stream[a]
Predef.UnsupportedOperationException -
if the stream is empty.
override
def
take
(n: scala.Int): scala.Stream[a]
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.
override
def
takeWhile
(p: (a) => scala.Boolean): scala.Stream[a]
p
.p -
the test predicate.
p
.
override
def
toString
: java.lang.String
def
zip
[b](that: scala.Stream[b]): scala.Stream[scala.Tuple2[a, b]]
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({a0,b0}, ..., {amin(m,n),bmin(m,n))}
when
Stream(a0, ..., am)
zip Stream(b0, ..., bn)
is invoked.
def
zipWithIndex
: scala.Stream[scala.Tuple2[a, scala.Int]]
Stream({a0,0}, {a0,1},...)
where ai
are the elements of this stream.