Scala Library Documentation


scala/Iterable.scala
]
trait
Iterable[+A]
extends
AnyRefelements
which returns an iterator over all the
elements contained in the collection.size
, it should also subtype Collection
. Only potentially unbounded collections should directly subclass Iterable
.Method Summary  
def

++
[B >: A](that : Iterable[B]) : Collection[B]
Appends two iterable objects.

def

/:
[B](z : B)(op : (B, A) => B) : B
Similar to
foldLeft but can be used as
an operator with the order of list 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 : String) : StringBuilder 
def

addString
(buf : StringBuilder, start : String, sep : String, end : String) : StringBuilder
Write all elements of this string into given string builder.

def

concat
[B >: A](that : Iterable[B]) : Collection[B]
Appends two iterable objects.

def

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

copyToBuffer
[B >: A](dest : Buffer[B]) : Unit
Copy all elements to a given buffer

def

drop
(n : Int) : Collection[A]
Returns this iterable without its
n first elements
If this iterable has less than n elements, the empty
iterable is returned. 
def

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

elements
: Iterator[A]
Creates a new iterator over all elements contained in this
object.

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) : Iterable[A]
Returns all the elements of this iterable that satisfy the
predicate
p . The order of the elements is preserved. 
def

find
(p : (A) => Boolean) : Option[A]
Find and return the first element of the iterable object satisfying a
predicate, if any.

def

findIndexOf
(p : (A) => Boolean) : Int
Returns index of the first element satisying a predicate, or 1.

def

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

foldLeft
[B](z : B)(op : (B, A) => B) : B
Combines the elements of this iterable object together using the binary
function
f , 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 list together using the binary
function
f , 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
(f : (A) => Unit) : Unit
Apply a function
f to all elements of this
iterable object. 
final def

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

indexOf
[B >: A](elem : B) : Int
Returns the index of the first occurence of the specified
object in this iterable object.

def

isEmpty
: Boolean
Is this collection empty?

def

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

mkString
(start : String, sep : String, end : String) : String
Returns a string representation of this iterable object. 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 . 
def

mkString
(sep : String) : 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

projection
: Projection[A]
returns a projection that can be used to call nonstrict
filter ,
map , and flatMap methods that build projections
of the collection. 
def

reduceLeft
[B >: A](op : (B, B) => B) : B
Combines the elements of this iterable object together using the binary
operator
op , from left to right 
def

reduceRight
[B >: A](op : (B, B) => B) : B
Combines the elements of this iterable object together using the binary
operator
op , from right to left 
def

sameElements
[B >: A](that : Iterable[B]) : Boolean
Checks if the other iterable object contains the same elements.

def

take
(n : Int) : Collection[A]
Returns an iterable consisting only over the first
n
elements of this iterable, or else the whole iterable, if it has less
than n elements. 
def

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

toList
: List[A]
Create a fresh list with all the elements of this iterable object.

Methods inherited from AnyRef  
getClass, hashCode, equals, clone, toString, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized 
Methods inherited from Any  
==, !=, isInstanceOf, asInstanceOf 
Method Details 
def
concat[B >: A](that : Iterable[B]) : Collection[B]
++
instead
def
++[B >: A](that : Iterable[B]) : Collection[B]
f
to each element of this iterable.f 
function to apply to each element.f(a_{0}), ..., f(a_{n})
if this iterable is a_{0}, ..., an
.f
to each element of
this iterable, then concatenates the results.f 
the function to apply on each element.f(a_{0}) ::: ... ::: f(a_{n})
if this iterable is a_{0}, ..., a_{n}
.p
. The order of the elements is preserved.p 
the predicate used to filter the list.p
.
def
takeWhile(p : (A) => Boolean) : Collection[A]
p
.p 
the test predicate.p
.
def
dropWhile(p : (A) => Boolean) : Collection[A]
p
.p 
the test predicate.p
.
def
take(n : Int) : Collection[A]
n
elements of this iterable, or else the whole iterable, if it has less
than n
elements.n 
the number of elements to take
def
drop(n : Int) : Collection[A]
n
first elements
If this iterable has less than n
elements, the empty
iterable is returned.n 
the number of elements to dropf
to all elements of this
iterable object.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 predicatep
to all elements of this
iterable object and return true, iff there is at least one
element for which p
yields true.p 
the predicatep 
the predicatep
, or None
if none exists.p 
the predicatep
, or 1 if such an element does not existelem 
element to search for.f
, from left to right, and starting with
the value z
.f(... (f(f(z, a_{0}), a_{1}) ...), a_{n})
if the list is
[a_{0}, a_{1}, ..., a_{n}]
.f
, from right to left, and starting with
the value z
.f(a_{0}, f(a_{1}, f(..., f(a_{n}, z)...)))
if the list is [a_{0}, a1, ..., a_{n}]
.foldLeft
but can be used as
an operator with the order of list and zero arguments reversed.
That is, z /: xs
is the same as xs foldLeft z
foldRight
.
That is, xs :\ z
is the same as xs foldRight z
op
, from left to rightop 
The operator to applyop(... op(a_{0},a_{1}), ..., a_{n})
if the iterable object has elements
a_{0}, a_{1}, ..., a_{n}
.op
, from right to leftop 
The operator to applya_{0} op (... op (a_{n1} op a_{n})...)
if the iterable object has elements a_{0}, a_{1}, ...,
a_{n}
.dest 
The buffer to which elements are copiedthat 
the other iterable objectstart
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
.List(1, 2, 3).mkString("(", "; ", ")") = "(1; 2; 3)"
start 
starting string.sep 
separator string.end 
ending string.toString()
)
are separated by the string sep
.sep 
separator string.
def
addString(buf : StringBuilder, start : String, sep : String, end : String) : StringBuilder
buf 
...
def
addString(buf : StringBuilder, sep : String) : StringBuilder
xs
with the elements of
this sequence starting at position start
.xs 
the array to fill.start 
starting index.
def
isEmpty : Boolean
def
projection : Projection[A]
filter
,
map
, and flatMap
methods that build projections
of the collection.final
def
hasDefiniteSize : Boolean
Collection
.
Many APIs in this trait will not work on collections of
unbound sizes.
Scala Library Documentation

