Scala Library
|
|
scala/collection/Iterator.scala
]
trait
Iterator[+A]
extends
AnyRefhasNext
method for checking
if there is a next element available, and a next
method
which returns the next element and discards it from the iterator.Method Summary | |
def
|
++
[B >: A](that : => Iterator[B]) : Iterator[B]
Returns a new iterator that first yields the elements of this
iterator followed by the elements provided by iterator
that . |
def
|
/:
[B](z : B)(op : (B, A) => B) : B
Similar to
foldLeft but can be used as
an operator with the order of iterator and zero arguments reversed.
That is, z /: xs is the same as xs foldLeft z . |
def
|
:\
[B](z : B)(op : (A, B) => B) : B
An alias for
foldRight .
That is, xs :\ z is the same as xs foldRight z . |
def
|
addString
(buf : StringBuilder, sep : java.lang.String) : StringBuilder
Write all elements of this iterator into given string builder.
The string representations of elements (w.r.t. the method
toString() )
are separated by the string sep . |
def
|
addString
(buf : StringBuilder, start : java.lang.String, sep : java.lang.String, end : java.lang.String) : StringBuilder
Write all elements of this iterator into given string builder.
The written text begins with the string
start and is finished by the string
end . Inside, the string representations of elements (w.r.t.
the method toString() ) are separated by the string
sep . |
def
|
addString
(buf : StringBuilder) : StringBuilder
Write all elements of this string into given string builder without using
any separator between consecutive elements.
|
def
|
append
[B >: A](that : Iterator[B]) : Iterator[B]
Returns a new iterator that first yields the elements of this
iterator followed by the elements provided by iterator
that . |
def
|
buffered
: BufferedIterator[A]
Returns a buffered iterator from this iterator.
|
def
|
collect
: Seq[A]
Collect elements into a seq.
|
def
|
contains
(elem : Any) : Boolean
Tests if the given value
elem is a member of this iterator. |
def
|
copyToArray
[B >: A](xs : Array[B], start : Int, len : Int) : Unit
Fills the given array `xs` with at most `len` elements of
this iterator starting at position `start` until either `len` elements have been copied,
or the end of the iterator is reached, or the end of the array `xs` is reached.
|
def
|
copyToArray
[B >: A](xs : Array[B]) : Unit
Fills the given array
xs with the elements of
this iterator starting at position 0
until either the end of the current iterator or the end of array `xs` is reached. |
def
|
copyToArray
[B >: A](xs : Array[B], start : Int) : Unit
Fills the given array
xs with the elements of
this iterator starting at position start
until either the end of the current iterator or the end of array `xs` is reached. |
def
|
copyToBuffer
[B >: A](dest : Buffer[B]) : Unit
Copy all elements to a buffer
|
def
|
counted
: CountedIterator[A]
Returns a counted iterator from this iterator.
|
def
|
drop
(n : Int) : Iterator[A]
Advances this iterator past the first
n elements,
or the length of the iterator, whichever is smaller. |
def
|
dropWhile
(p : (A) => Boolean) : Iterator[A]
Skips longest sequence of elements of this iterator which satisfy given
predicate
p , and returns an iterator of the remaining elements. |
def
|
duplicate
: (Iterator[A], Iterator[A])
Creates two new iterators that both iterate over the same elements
as this iterator (in the same order).
|
def
|
exists
(p : (A) => Boolean) : Boolean
Apply a predicate
p to all elements of this
iterable object and return true iff there is at least one
element for which p yields true . |
def
|
filter
(p : (A) => Boolean) : Iterator[A]
Returns an iterator over all the elements of this iterator that
satisfy the predicate
p . The order of the elements
is preserved. |
def
|
filterNot
(p : (A) => Boolean) : Iterator[A]
Returns an iterator over all the elements of this iterator which
do not satisfy the predicate
p . |
def
|
find
(p : (A) => Boolean) : Option[A]
Find and return the first value returned by the iterator satisfying a
predicate, if any.
|
def
|
findIndexOf
(p : (A) => Boolean) : Int
Returns index of the first element satisfying a predicate, or -1.
|
def
|
flatMap
[B](f : (A) => Iterator[B]) : Iterator[B]
Applies the given function
f to each element of
this iterator, then concatenates the results. |
def
|
foldLeft
[B](z : B)(op : (B, A) => B) : B
Combines the elements of this iterator together using the binary
operator
op , from left to right, and starting with
the value z . |
def
|
foldRight
[B](z : B)(op : (A, B) => B) : B
Combines the elements of this iterator together using the binary
operator
op , from right to left, and starting with
the value z . |
def
|
forall
(p : (A) => Boolean) : Boolean
Apply a predicate
p to all elements of this
iterable object and return true iff the predicate yields
true for all elements. |
def
|
foreach
[U](f : (A) => U) : Unit
Execute a function
f for all elements of this
iterator. |
def
|
grouped
[B >: A](size : Int) : GroupedIterator[B]
Returns an iterator which groups this iterator into fixed size
blocks. Example usages:
// Returns List(List(1, 2, 3), List(4, 5, 6), List(7))) (1 to 7).iterator grouped 3 toList // Returns List(List(1, 2, 3), List(4, 5, 6)) (1 to 7).iterator grouped 3 withPartial false toList // Returns List(List(1, 2, 3), List(4, 5, 6), List(7, 20, 25) // Illustrating that withPadding's argument is by-name. val it2 = Iterator.iterate(20)(_ + 5) (1 to 7).iterator grouped 3 withPadding it2.next toList |
abstract def
|
hasNext
: Boolean
Does this iterator provide another element?
|
def
|
indexOf
[B >: A](elem : B) : Int
Returns the index of the first occurence of the specified
object in this iterable object.
|
def
|
indexWhere
(p : (A) => Boolean) : Int
Returns index of the first element satisfying a predicate, or -1.
|
def
|
length
: Int
Returns the number of elements in this iterator.
|
def
|
map
[B](f : (A) => B) : Iterator[B]
Returns a new iterator that maps all elements of this iterator
to new elements using function
f . |
def
|
mkString
(sep : java.lang.String) : java.lang.String
Returns a string representation of this iterable object. The string
representations of elements (w.r.t. the method
toString() )
are separated by the string sep . |
def
|
mkString
: java.lang.String
Returns a string representation of this iterable object. The string
representations of elements (w.r.t. the method
toString() )
are concatenated without any separator string. |
def
|
mkString
(start : java.lang.String, sep : java.lang.String, end : java.lang.String) : java.lang.String
Returns a string representation of the elements in this iterator. The resulting string
begins with the string
start and is finished by the string
end . Inside, the string representations of elements (w.r.t.
the method toString ) are separated by the string
sep .
Ex: List(1, 2, 3).mkString("(", "; ", ")") = "(1; 2; 3)" |
abstract def
|
next
: A
Returns the next element of this iterator.
|
def
|
padTo
[A1 >: A](len : Int, elem : A1) : Iterator[A1]
Return a new iterator with a length equal or longer to
len .
If the current iterator returns fewer than `len` elements
return `elem` until the required length `len` is reached. |
def
|
partialMap
[B](pf : PartialFunction[Any, B]) : Iterator[B]
Returns a new iterator based on the partial function
pf ,
containing pf(x) for all the elements which are defined on pf.
The order of the elements is preserved. |
def
|
partition
(p : (A) => Boolean) : (Iterator[A], Iterator[A])
Partitions this iterator in two iterators according to a predicate.
|
def
|
patch
[B >: A](from : Int, patchElems : Iterator[B], replaced : Int) : Iterator[B]
Returns this iterator with patched values.
|
def
|
readInto [B >: A](xs : Array[B]) : Unit |
def
|
readInto [B >: A](xs : Array[B], start : Int) : Unit |
def
|
readInto
[B >: A](xs : Array[B], start : Int, sz : Int) : Unit
Fills the given array
xs with the elements of
this sequence starting at position start . Like copyToArray ,
but designed to accomodate IO stream operations. |
def
|
reduceLeft
[B >: A](op : (B, A) => B) : B
Combines the elements of this iterator together using the binary
operator
op , from left to right. |
def
|
reduceLeftOption
[B >: A](op : (B, A) => B) : Option[B]
Combines the elements of this iterator together using the binary
operator
op , from left to right |
def
|
reduceRight
[B >: A](op : (A, B) => B) : B
Combines the elements of this iterator together using the binary
operator
op , from right to left |
def
|
reduceRightOption
[B >: A](op : (A, B) => B) : Option[B]
Combines the elements of this iterable object together using the binary
operator
op , from right to left. |
def
|
slice
(from : Int, until : Int) : Iterator[A]
Advances this iterator past the first `from` elements using `drop`,
and then takes `until - from` elements, using `take`.
|
def
|
sliding
[B >: A](size : Int, step : Int) : GroupedIterator[B]
Returns an iterator which presents a "sliding window" view of
another iterator. The first argument is the window size, and
the second is how far to advance the window on each iteration;
defaults to 1. Example usages:
// Returns List(List(1, 2, 3), List(2, 3, 4), List(3, 4, 5)) (1 to 5).iterator.sliding(3).toList // Returns List(List(1, 2, 3, 4), List(4, 5)) (1 to 5).iterator.sliding(4, 3).toList // Returns List(List(1, 2, 3, 4)) (1 to 5).iterator.sliding(4, 3).withPartial(false).toList // Returns List(List(1, 2, 3, 4), List(4, 5, 20, 25)) // Illustrating that withPadding's argument is by-name. val it2 = Iterator.iterate(20)(_ + 5) (1 to 5).iterator.sliding(4, 3).withPadding(it2.next).toList |
def
|
take
(n : Int) : Iterator[A]
Returns a new iterator that iterates only over the first
n
elements of this iterator, or the length of the iterator, whichever is smaller. |
def
|
takeWhile
(p : (A) => Boolean) : Iterator[A]
Returns an iterator over the longest prefix of this iterator such that
all elements of the result satisfy the predicate
p .
The order of the elements is preserved. |
def
|
toList
: List[A]
Traverse this iterator and return all elements in a list.
|
def
|
toSeq
: Seq[A]
Traverse this iterator and return all elements in a sequence.
|
def
|
toStream
: Stream[A]
Traverse this iterator and return all elements in a stream.
|
override def
|
toString
: java.lang.String
Returns a string representation of the object.
|
def
|
zip
[B](that : Iterator[B]) : Iterator[(A, B)]
Return an iterator formed from this iterator and the specified iterator
that by associating each element of the former with
the element at the same position in the latter.
If one of the two iterators is longer than the other, its remaining
elements are ignored. |
def
|
zipAll
[B, A1 >: A, B1 >: B](that : Iterator[B], thisElem : A1, thatElem : B1) : Iterator[(A1, B1)]
Returns an iterator formed from this iterator and the specified iterator
that by associating each element of the former with
the element at the same position in the latter. |
def
|
zipWithIndex
: Iterator[(A, Int)]
Return an iterator that pairs each element of this iterator
with its index, counting from 0.
|
Methods inherited from AnyRef | |
getClass, hashCode, equals, clone, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized |
Methods inherited from Any | |
==, !=, isInstanceOf, asInstanceOf |
Class Summary | |
class
|
GroupedIterator
[B >: A](self : Iterator[A], size : Int, step : Int) extends Iterator[Seq[B]]
A flexible iterator for transforming an
Iterator[A] into an
Iterator[Seq[A]], with configurable sequence size, step, and
strategy for dealing with elements which don't fit evenly.
Typical uses can be achieved via methods `grouped' and `sliding'. |
Method Details |
abstract
def
hasNext : Boolean
abstract
def
next : A
n
elements of this iterator, or the length of the iterator, whichever is smaller.n -
the number of elements to taken
elements,
or the length of the iterator, whichever is smaller.n -
the number of elements to dropfrom -
The index of the first element of the sliceuntil -
The index of the element following the slicef
.that
.f
to each element of
this iterator, then concatenates the results.f -
the function to apply on each element.f(a0), ... , f(an)
if this iterator yields the
elements a0, ..., an
.p
. The order of the elements
is preserved.p -
the predicate used to filter the iterator.p
.p
.p -
the predicate used to filter.p
.
def
partialMap[B](pf : PartialFunction[Any, B]) : Iterator[B]
pf
,
containing pf(x)
for all the elements which are defined on pf.
The order of the elements is preserved.pf -
the partial function which filters and maps the iterator.p
.
The order of the elements is preserved.p -
the predicate used to filter the iterator.p
.p -
the predicate on which to partitionp
and the iterator that does not.
The relative order of the elements in the resulting iterators
is the same as in the original iterator.p
, and returns an iterator of the remaining elements.p -
the predicate used to skip elements.that
by associating each element of the former with
the element at the same position in the latter.
If one of the two iterators is longer than the other, its remaining
elements are ignored.len
.
If the current iterator returns fewer than `len` elements
return `elem` until the required length `len` is reached.
def
zipAll[B, A1 >: A, B1 >: B](that : Iterator[B], thisElem : A1, thatElem : B1) : Iterator[(A1, B1)]
that
by associating each element of the former with
the element at the same position in the latter.that -
iterator that
may have a different length as the self iterator.thisElem -
element thisElem
is used to fill up the resulting iterator if the self iterator is shorter than
that
thatElem -
element thatElem
is used to fill up the resulting iterator if that
is shorter than
the self iteratorIterator((a0,b0), ..., (an,bn), (elem,bn+1),
..., {elem,bm})
when [a0, ..., an] zip
[b0, ..., bm]
is
invoked where m > n
.f
for all elements of this
iterator.f -
a function that is applied to every element.p
to all elements of this
iterable object and return true
iff the predicate yields
true
for all elements.p -
the predicatetrue
iff the predicate yields true
for all elements.p
to all elements of this
iterable object and return true iff there is at least one
element for which p
yields true
.p -
the predicatetrue
iff the predicate yields true
for at least one element.elem
is a member of this iterator.elem -
element whose membership has to be tested.p -
the predicatep
, or None
if none exists.p -
the predicatep
, or -1 if such an element does not existelem -
element to search for.op
, from left to right, and starting with
the value z
.op(... (op(op(z,a0),a1) ...), an)
if the iterator yields elements
a0, a1, ..., an
.op
, from right to left, and starting with
the value z
.a0 op (... op (an op z)...)
if the iterator yields elements a0, a1, ...,
an
.foldLeft
but can be used as
an operator with the order of iterator and zero arguments reversed.
That is, z /: xs
is the same as xs foldLeft z
.z -
the left argument of the first application of op
(evaluation occurs from left to right).op -
the applied operator.foldLeft
.foldRight
.
That is, xs :\ z
is the same as xs foldRight z
.z -
the right argument of the first application of op
(evaluation occurs from right to left).op -
the applied operator.foldRight
.op
, from left to right.op -
The operator to applyop(... op(a0,a1), ..., an)
if the iterator yields elements
a0, a1, ..., an
.op
, from right to leftop -
The operator to applya0 op (... op (an-1 op an)...)
if the iterator yields elements a0, a1, ...,
an
.op
, from left to rightop -
The operator to applyop
, from right to left.op -
The operator to apply
def
buffered : BufferedIterator[A]
def
grouped[B >: A](size : Int) : GroupedIterator[B]
// Returns List(List(1, 2, 3), List(4, 5, 6), List(7))) (1 to 7).iterator grouped 3 toList // Returns List(List(1, 2, 3), List(4, 5, 6)) (1 to 7).iterator grouped 3 withPartial false toList // Returns List(List(1, 2, 3), List(4, 5, 6), List(7, 20, 25) // Illustrating that withPadding's argument is by-name. val it2 = Iterator.iterate(20)(_ + 5) (1 to 7).iterator grouped 3 withPadding it2.next toList
def
sliding[B >: A](size : Int, step : Int) : GroupedIterator[B]
// Returns List(List(1, 2, 3), List(2, 3, 4), List(3, 4, 5)) (1 to 5).iterator.sliding(3).toList // Returns List(List(1, 2, 3, 4), List(4, 5)) (1 to 5).iterator.sliding(4, 3).toList // Returns List(List(1, 2, 3, 4)) (1 to 5).iterator.sliding(4, 3).withPartial(false).toList // Returns List(List(1, 2, 3, 4), List(4, 5, 20, 25)) // Illustrating that withPadding's argument is by-name. val it2 = Iterator.iterate(20)(_ + 5) (1 to 5).iterator.sliding(4, 3).withPadding(it2.next).toList
def
length : Int
from -
The start index from which to patchps -
The iterator of patch valuesreplaced -
The number of values in the original iterator that are replaced by the patch.xs -
the array to fill.start -
starting index.len -
number of elements to copyxs
with the elements of
this iterator starting at position start
until either the end of the current iterator or the end of array `xs` is reached.xs -
the array to fill.start -
starting index.xs
with the elements of
this iterator starting at position 0
until either the end of the current iterator or the end of array `xs` is reached.xs -
the array to fill.dest -
The buffer to which elements are copied
def
mkString(start : java.lang.String, sep : java.lang.String, end : java.lang.String) : java.lang.String
start
and is finished by the string
end
. Inside, the string representations of elements (w.r.t.
the method toString
) are separated by the string
sep
.
Ex: List(1, 2, 3).mkString("(", "; ", ")") = "(1; 2; 3)"
start -
starting string.sep -
separator string.end -
ending string.
def
mkString(sep : java.lang.String) : java.lang.String
toString()
)
are separated by the string sep
.sep -
separator string.
def
mkString : java.lang.String
toString()
)
are concatenated without any separator string.
def
addString(buf : StringBuilder, start : java.lang.String, sep : java.lang.String, end : java.lang.String) : StringBuilder
start
and is finished by the string
end
. Inside, the string representations of elements (w.r.t.
the method toString()
) are separated by the string
sep
.
def
addString(buf : StringBuilder, sep : java.lang.String) : StringBuilder
toString()
)
are separated by the string sep
.
def
addString(buf : StringBuilder) : StringBuilder
override
def
toString : java.lang.String
The default representation is platform dependent.
that
.
def
findIndexOf(p : (A) => Boolean) : Int
def
collect : Seq[A]
def
counted : CountedIterator[A]
def
readInto[B >: A](xs : Array[B], start : Int, sz : Int) : Unit
xs
with the elements of
this sequence starting at position start
. Like copyToArray
,
but designed to accomodate IO stream operations.xs -
the array to fill.start -
the starting index.sz -
the maximum number of elements to be read.sz
elements.
def
readInto[B >: A](xs : Array[B]) : Unit
Scala Library
|
|