trait IterableOps[+A, +CC[_], +C] extends IterableOnce[A]
Base trait for Iterable operations
VarianceNote
We require that for all child classes of Iterable the variance of
the child class and the variance of the C parameter passed to IterableOps
are the same. We cannot express this since we lack variance polymorphism. That's
why we have to resort at some places to write C[A @uncheckedVariance].
- CC
type constructor of the collection (e.g.
List,Set). Operations returning a collection with a different type of elementB(e.g.map) return aCC[B].- C
type of the collection (e.g.
List[Int],String,BitSet). Operations returning a collection with the same type of element (e.g.drop,filter) return aC.
- Alphabetic
- By Inheritance
- IterableOps
- IterableOnce
- Any
- by iterableOnceExtensionMethods
- Hide All
- Show All
- Public
- All
Type Members
-
class
WithFilter extends collection.WithFilter[A, CC]
A template trait that contains just the
map,flatMap,foreachandwithFiltermethods of traitIterable.
Abstract Value Members
-
abstract
def
coll: C
- returns
This collection as a
C.
- Attributes
- protected[this]
-
abstract
def
fromSpecificIterable(coll: Iterable[A]): C
Defines how to turn a given
Iterable[A]into a collection of typeC.Defines how to turn a given
Iterable[A]into a collection of typeC.This process can be done in a strict way or a non-strict way (ie. without evaluating the elements of the resulting collections). In other words, this methods defines the evaluation model of the collection.
- Attributes
- protected[this]
-
abstract
def
getClass(): Class[_]
- Definition Classes
- Any
-
abstract
def
iterableFactory: IterableFactoryLike[CC]
- returns
The companion object of this iterable collection, providing various factory methods.
-
abstract
def
iterator(): Iterator[A]
Iterator can be used only once
Iterator can be used only once
- Definition Classes
- IterableOnce
-
abstract
def
newSpecificBuilder(): Builder[A, C]
- returns
a strict builder for the same collection type. Note that in the case of lazy collections (e.g. View or immutable.LazyList), it is possible to implement this method but the resulting
Builderwill break laziness. As a consequence, operations should preferably be implemented withfromSpecificIterableinstead of this method.
- Attributes
- protected[this]
-
abstract
def
toIterable: Iterable[A]
- returns
This collection as an
Iterable[A]. No new collection will be built ifthisis already anIterable[A].
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- Any
-
final
def
##(): Int
- Definition Classes
- Any
-
final
def
++[B >: A](suffix: Iterable[B]): CC[B]
Alias for
concatAlias for
concat- Annotations
- @inline()
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
className: String
The class name of this collection.
The class name of this collection. To be used for converting to string. Collections generally print like this:
<className>(elem_1, ..., elem_n)
- returns
a string representation which starts the result of
toStringapplied to this iterable collection. By default the string prefix is the simple name of the collection class iterable collection.
-
def
collect[B](pf: PartialFunction[A, B]): CC[B]
Builds a new collection by applying a partial function to all elements of this iterable collection on which the function is defined.
Builds a new collection by applying a partial function to all elements of this iterable collection on which the function is defined.
- B
the element type of the returned collection.
- pf
the partial function which filters and maps the iterable collection.
- returns
a new iterable collection resulting from applying the given partial function
pfto each element on which it is defined and collecting the results. The order of the elements is preserved.
-
def
collectFirst[B](pf: PartialFunction[A, B]): Option[B]
Finds the first element of the iterable collection for which the given partial function is defined, and applies the partial function to it.
Finds the first element of the iterable collection for which the given partial function is defined, and applies the partial function to it.
Note: may not terminate for infinite-sized collections.
Note: might return different results for different runs, unless the underlying collection type is ordered.
- pf
the partial function
- returns
an option value containing pf applied to the first value for which it is defined, or
Noneif none exists.
Seq("a", 1, 5L).collectFirst({ case x: Int => x*10 }) = Some(10)
Example: -
def
concat[B >: A](suffix: Iterable[B]): CC[B]
Returns a new iterable collection containing the elements from the left hand operand followed by the elements from the right hand operand.
Returns a new iterable collection containing the elements from the left hand operand followed by the elements from the right hand operand. The element type of the iterable collection is the most specific superclass encompassing the element types of the two operands.
- B
the element type of the returned collection.
- suffix
the traversable to append.
- returns
a new iterable collection which contains all elements of this iterable collection followed by all elements of
suffix.
-
def
copyToArray[B >: A](xs: Array[B], start: Int = 0): xs.type
Copy all elements of this collection to array
xs, starting atstart. -
def
count(p: (A) ⇒ Boolean): Int
Counts the number of elements in the iterable collection which satisfy a predicate.
Counts the number of elements in the iterable collection which satisfy a predicate.
- p
the predicate used to test elements.
- returns
the number of elements satisfying the predicate
p.
-
def
drop(n: Int): C
The rest of the collection without its
nfirst elements.The rest of the collection without its
nfirst elements. For linear, immutable collections this should avoid making a copy. -
def
dropRight(n: Int): C
The rest of the collection without its
nlast elements.The rest of the collection without its
nlast elements. For linear, immutable collections this should avoid making a copy. -
def
dropWhile(p: (A) ⇒ Boolean): C
Drops longest prefix of elements that satisfy a predicate.
Drops longest prefix of elements that satisfy a predicate.
Note: might return different results for different runs, unless the underlying collection type is ordered.
- p
The predicate used to test elements.
- returns
the longest suffix of this iterable collection whose first element does not satisfy the predicate
p.
-
def
equals(arg0: Any): Boolean
- Definition Classes
- Any
-
def
exists(p: (A) ⇒ Boolean): Boolean
Tests whether a predicate holds for at least one element of this iterable collection.
Tests whether a predicate holds for at least one element of this iterable collection.
Note: may not terminate for infinite-sized collections.
- p
the predicate used to test elements.
- returns
trueif the given predicatepis satisfied by at least one element of this iterable collection, otherwisefalse
-
def
filter(pred: (A) ⇒ Boolean): C
Selects all elements of this iterable collection which satisfy a predicate.
Selects all elements of this iterable collection which satisfy a predicate.
- pred
the predicate used to test elements.
- returns
a new iterable collection consisting of all elements of this iterable collection that satisfy the given predicate
pred. Their order may not be preserved.
-
def
filterNot(pred: (A) ⇒ Boolean): C
Selects all elements of this iterable collection which do not satisfy a predicate.
Selects all elements of this iterable collection which do not satisfy a predicate.
- pred
the predicate used to test elements.
- returns
a new iterable collection consisting of all elements of this iterable collection that do not satisfy the given predicate
pred. Their order may not be preserved.
-
def
find(p: (A) ⇒ Boolean): Option[A]
Finds the first element of the iterable collection satisfying a predicate, if any.
Finds the first element of the iterable collection satisfying a predicate, if any.
Note: may not terminate for infinite-sized collections.
Note: might return different results for different runs, unless the underlying collection type is ordered.
- p
the predicate used to test elements.
- returns
an option value containing the first element in the iterable collection that satisfies
p, orNoneif none exists.
-
def
flatMap[B](f: (A) ⇒ IterableOnce[B]): CC[B]
Builds a new collection by applying a function to all elements of this iterable collection and using the elements of the resulting collections.
Builds a new collection by applying a function to all elements of this iterable collection and using the elements of the resulting collections.
For example:
def getWords(lines: Seq[String]): Seq[String] = lines flatMap (line => line split "\\W+")
The type of the resulting collection is guided by the static type of iterable collection. This might cause unexpected results sometimes. For example:
// lettersOf will return a Seq[Char] of likely repeated letters, instead of a Set def lettersOf(words: Seq[String]) = words flatMap (word => word.toSet) // lettersOf will return a Set[Char], not a Seq def lettersOf(words: Seq[String]) = words.toSet flatMap (word => word.toSeq) // xs will be an Iterable[Int] val xs = Map("a" -> List(11,111), "b" -> List(22,222)).flatMap(_._2) // ys will be a Map[Int, Int] val ys = Map("a" -> List(1 -> 11,1 -> 111), "b" -> List(2 -> 22,2 -> 222)).flatMap(_._2)
- B
the element type of the returned collection.
- f
the function to apply to each element.
- returns
a new iterable collection resulting from applying the given collection-valued function
fto each element of this iterable collection and concatenating the results.
-
def
flatten[B](implicit asIterable: (A) ⇒ IterableOnce[B]): CC[B]
Converts this iterable collection of traversable collections into a iterable collection formed by the elements of these traversable collections.
Converts this iterable collection of traversable collections into a iterable collection formed by the elements of these traversable collections.
The resulting collection's type will be guided by the type of iterable collection. For example:
val xs = List( Set(1, 2, 3), Set(1, 2, 3) ).flatten // xs == List(1, 2, 3, 1, 2, 3) val ys = Set( List(1, 2, 3), List(3, 2, 1) ).flatten // ys == Set(1, 2, 3)
- B
the type of the elements of each traversable collection.
- asIterable
an implicit conversion which asserts that the element type of this iterable collection is a
GenTraversable.- returns
a new iterable collection resulting from concatenating all element iterable collections.
-
def
foldLeft[B](z: B)(op: (B, A) ⇒ B): B
Applies a binary operator to a start value and all elements of this iterable collection, going left to right.
Applies a binary operator to a start value and all elements of this iterable collection, going left to right.
Note: will not terminate for infinite-sized collections.
Note: might return different results for different runs, unless the underlying collection type is ordered or the operator is associative and commutative.
- B
the result type of the binary operator.
- z
the start value.
- op
the binary operator.
- returns
the result of inserting
opbetween consecutive elements of this iterable collection, going left to right with the start valuezon the left:op(...op(z, x_1), x_2, ..., x_n)
where
x1, ..., xnare the elements of this iterable collection. Returnszif this iterable collection is empty.
-
def
foldRight[B](z: B)(op: (A, B) ⇒ B): B
Applies a binary operator to all elements of this iterable collection and a start value, going right to left.
Applies a binary operator to all elements of this iterable collection and a start value, going right to left.
Note: will not terminate for infinite-sized collections.
Note: might return different results for different runs, unless the underlying collection type is ordered or the operator is associative and commutative.
- B
the result type of the binary operator.
- z
the start value.
- op
the binary operator.
- returns
the result of inserting
opbetween consecutive elements of this iterable collection, going right to left with the start valuezon the right:op(x_1, op(x_2, ... op(x_n, z)...))
where
x1, ..., xnare the elements of this iterable collection. Returnszif this iterable collection is empty.
-
def
forall(p: (A) ⇒ Boolean): Boolean
Tests whether a predicate holds for all elements of this iterable collection.
Tests whether a predicate holds for all elements of this iterable collection.
Note: may not terminate for infinite-sized collections.
- p
the predicate used to test elements.
- returns
trueif this iterable collection is empty or the given predicatepholds for all elements of this iterable collection, otherwisefalse.
-
def
foreach[U](f: (A) ⇒ U): Unit
Apply
fto each element for its side effects Note: [U] parameter needed to help scalac's type inference. -
final
def
fromIterable[E](it: Iterable[E]): CC[E]
Similar to
fromSpecificIterable, but for a (possibly) different type of element.Similar to
fromSpecificIterable, but for a (possibly) different type of element. Note that the return type is knowCC[E].- Attributes
- protected[this]
- Annotations
- @inline()
-
def
groupBy[K](f: (A) ⇒ K): immutable.Map[K, C]
Partitions this iterable collection into a map of iterable collections according to some discriminator function.
Partitions this iterable collection into a map of iterable collections according to some discriminator function.
Note: When applied to a view or a lazy collection it will always force the elements.
- K
the type of keys returned by the discriminator function.
- f
the discriminator function.
- returns
A map from keys to iterable collections such that the following invariant holds:
(xs groupBy f)(k) = xs filter (x => f(x) == k)That is, every key
kis bound to a iterable collection of those elementsxfor whichf(x)equalsk.
-
def
groupMap[K, B](key: (A) ⇒ K)(f: (A) ⇒ B): immutable.Map[K, CC[B]]
Partitions this iterable collection into a map of iterable collections according to a discriminator function
key.Partitions this iterable collection into a map of iterable collections according to a discriminator function
key. Each element in a group is transformed into a value of typeBusing thevaluefunction.It is equivalent to
groupBy(key).mapValues(_.map(f)), but more efficient.case class User(name: String, age: Int) def namesByAge(users: Seq[User]): Map[Int, Seq[String]] = users.groupMap(_.age)(_.name)
- K
the type of keys returned by the discriminator function
- B
the type of values returned by the transformation function
- key
the discriminator function
- f
the element transformation function
-
def
groupMapReduce[K, B](key: (A) ⇒ K)(f: (A) ⇒ B)(reduce: (B, B) ⇒ B): immutable.Map[K, B]
Partitions this iterable collection into a map according to a discriminator function
key.Partitions this iterable collection into a map according to a discriminator function
key. All the values that have the same discriminator are then transformed by thevaluefunction and then reduced into a single value with thereducefunction.It is equivalent to
groupBy(key).mapValues(_.map(f).reduce(reduce)), but more efficient.def occurrences[A](as: Seq[A]): Map[A, Int] = as.groupMapReduce(identity)(_ => 1)(_ + _)
-
def
grouped(size: Int): Iterator[C]
Partitions elements in fixed size iterable collections.
Partitions elements in fixed size iterable collections.
- size
the number of elements per group
- returns
An iterator producing iterable collections of size
size, except the last will be less than sizesizeif the elements don't divide evenly.
- See also
scala.collection.Iterator, method
grouped
-
def
hashCode(): Int
- Definition Classes
- Any
-
def
head: A
Selects the first element of this iterable collection.
Selects the first element of this iterable collection.
Note: might return different results for different runs, unless the underlying collection type is ordered.
- returns
the first element of this iterable collection.
- Exceptions thrown
NoSuchElementExceptionif the iterable collection is empty.
-
def
headOption: Option[A]
Optionally selects the first element.
Optionally selects the first element.
Note: might return different results for different runs, unless the underlying collection type is ordered.
- returns
the first element of this iterable collection if it is nonempty,
Noneif it is empty.
-
def
init: C
The initial part of the collection without its last element.
-
def
isEmpty: Boolean
Tests whether the iterable collection is empty.
Tests whether the iterable collection is empty.
Note: Implementations in subclasses that are not repeatedly traversable must take care not to consume any elements when
isEmptyis called.- returns
trueif the iterable collection contains no elements,falseotherwise.
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
knownSize: Int
The number of elements in this collection, if it can be cheaply computed, -1 otherwise.
The number of elements in this collection, if it can be cheaply computed, -1 otherwise. Cheaply usually means: Not requiring a collection traversal.
- returns
The number of elements of this iterable collection if it can be computed in O(1) time, otherwise -1
- Definition Classes
- IterableOps → IterableOnce
-
def
last: A
Selects the last element.
Selects the last element.
Note: might return different results for different runs, unless the underlying collection type is ordered.
- returns
The last element of this iterable collection.
- Exceptions thrown
NoSuchElementExceptionIf the iterable collection is empty.
-
def
lastOption: Option[A]
Optionally selects the last element.
Optionally selects the last element.
Note: might return different results for different runs, unless the underlying collection type is ordered.
- returns
the last element of this iterable collection$ if it is nonempty,
Noneif it is empty.
-
def
map[B](f: (A) ⇒ B): CC[B]
Builds a new collection by applying a function to all elements of this iterable collection.
Builds a new collection by applying a function to all elements of this iterable collection.
- B
the element type of the returned collection.
- f
the function to apply to each element.
- returns
a new iterable collection resulting from applying the given function
fto each element of this iterable collection and collecting the results.
-
def
max: A
[use case] Finds the largest element.
[use case]Finds the largest element.
- returns
the largest element of this iterable collection.
Full Signaturedef max[B >: A](implicit ord: Ordering[B]): A
-
def
maxBy[B](f: (A) ⇒ B): A
[use case] Finds the first element which yields the largest value measured by function f.
[use case]Finds the first element which yields the largest value measured by function f.
- B
The result type of the function f.
- f
The measuring function.
- returns
the first element of this iterable collection with the largest value measured by function f.
Full Signaturedef maxBy[B](f: (A) ⇒ B)(implicit cmp: Ordering[B]): A
-
def
min: A
[use case] Finds the smallest element.
[use case]Finds the smallest element.
- returns
the smallest element of this iterable collection
Full Signaturedef min[B >: A](implicit ord: Ordering[B]): A
-
def
minBy[B](f: (A) ⇒ B): A
[use case] Finds the first element which yields the smallest value measured by function f.
[use case]Finds the first element which yields the smallest value measured by function f.
- B
The result type of the function f.
- f
The measuring function.
- returns
the first element of this iterable collection with the smallest value measured by function f.
Full Signaturedef minBy[B](f: (A) ⇒ B)(implicit cmp: Ordering[B]): A
-
def
mkString: String
Displays all elements of this iterable collection in a string.
Displays all elements of this iterable collection in a string.
- returns
a string representation of this iterable collection. In the resulting string the string representations (w.r.t. the method
toString) of all elements of this iterable collection follow each other without any separator string.
-
def
mkString(sep: String): String
Displays all elements of this iterable collection in a string using a separator string.
Displays all elements of this iterable collection in a string using a separator string.
- sep
the separator string.
- returns
a string representation of this iterable collection. In the resulting string the string representations (w.r.t. the method
toString) of all elements of this iterable collection are separated by the stringsep.
List(1, 2, 3).mkString("|") = "1|2|3"
Example: -
def
mkString(start: String, sep: String, end: String): String
Displays all elements of this iterable collection in a string using start, end, and separator strings.
Displays all elements of this iterable collection in a string using start, end, and separator strings.
- start
the starting string.
- sep
the separator string.
- end
the ending string.
- returns
a string representation of this iterable collection. The resulting string begins with the string
startand ends with the stringend. Inside, the string representations (w.r.t. the methodtoString) of all elements of this iterable collection are separated by the stringsep.
List(1, 2, 3).mkString("(", "; ", ")") = "(1; 2; 3)"
Example: -
def
nonEmpty: Boolean
Tests whether the iterable collection is not empty.
Tests whether the iterable collection is not empty.
- returns
trueif the iterable collection contains at least one element,falseotherwise.
-
def
partition(p: (A) ⇒ Boolean): (C, C)
A pair of, first, all elements that satisfy prediacte
pand, second, all elements that do not.A pair of, first, all elements that satisfy prediacte
pand, second, all elements that do not. Interesting because it splits a collection in two.The default implementation provided here needs to traverse the collection twice. Strict collections have an overridden version of
partitioninBuildable, which requires only a single traversal. -
def
product: A
[use case] Multiplies up the elements of this collection.
[use case]Multiplies up the elements of this collection.
- returns
the product of all elements in this iterable collection of numbers of type
Int. Instead ofInt, any other typeTwith an implicitNumeric[T]implementation can be used as element type of the iterable collection and as result type ofproduct. Examples of such types are:Long,Float,Double,BigInt.
Full Signaturedef product[B >: A](implicit num: Numeric[B]): B
-
def
reduce[B >: A](op: (B, B) ⇒ B): B
Reduces the elements of this iterable collection using the specified associative binary operator.
Reduces the elements of this iterable collection using the specified associative binary operator.
The order in which operations are performed on elements is unspecified and may be nondeterministic.
- B
A type parameter for the binary operator, a supertype of
A.- op
A binary operator that must be associative.
- returns
The result of applying reduce operator
opbetween all the elements if the iterable collection is nonempty.
- Exceptions thrown
UnsupportedOperationExceptionif this iterable collection is empty.
-
def
reduceLeft[B >: A](op: (B, A) ⇒ B): B
Applies a binary operator to all elements of this iterable collection, going left to right.
Applies a binary operator to all elements of this iterable collection, going left to right.
Note: will not terminate for infinite-sized collections.
Note: might return different results for different runs, unless the underlying collection type is ordered or the operator is associative and commutative.
- B
the result type of the binary operator.
- op
the binary operator.
- returns
the result of inserting
opbetween consecutive elements of this iterable collection, going left to right:op( op( ... op(x_1, x_2) ..., x_{n-1}), x_n)where
x1, ..., xnare the elements of this iterable collection.
- Exceptions thrown
UnsupportedOperationExceptionif this iterable collection is empty.
-
def
reduceLeftOption[B >: A](op: (B, A) ⇒ B): Option[B]
Optionally applies a binary operator to all elements of this iterable collection, going left to right.
Optionally applies a binary operator to all elements of this iterable collection, going left to right.
Note: will not terminate for infinite-sized collections.
Note: might return different results for different runs, unless the underlying collection type is ordered or the operator is associative and commutative.
- B
the result type of the binary operator.
- op
the binary operator.
- returns
an option value containing the result of
reduceLeft(op)if this iterable collection is nonempty,Noneotherwise.
-
def
reduceOption[B >: A](op: (B, B) ⇒ B): Option[B]
Reduces the elements of this iterable collection, if any, using the specified associative binary operator.
Reduces the elements of this iterable collection, if any, using the specified associative binary operator.
The order in which operations are performed on elements is unspecified and may be nondeterministic.
- B
A type parameter for the binary operator, a supertype of
A.- op
A binary operator that must be associative.
- returns
An option value containing result of applying reduce operator
opbetween all the elements if the collection is nonempty, andNoneotherwise.
-
def
reduceRight[B >: A](op: (A, B) ⇒ B): B
Applies a binary operator to all elements of this iterable collection, going right to left.
Applies a binary operator to all elements of this iterable collection, going right to left.
Note: will not terminate for infinite-sized collections.
Note: might return different results for different runs, unless the underlying collection type is ordered or the operator is associative and commutative.
- B
the result type of the binary operator.
- op
the binary operator.
- returns
the result of inserting
opbetween consecutive elements of this iterable collection, going right to left:op(x_1, op(x_2, ..., op(x_{n-1}, x_n)...))where
x1, ..., xnare the elements of this iterable collection.
- Exceptions thrown
UnsupportedOperationExceptionif this iterable collection is empty.
-
def
reduceRightOption[B >: A](op: (A, B) ⇒ B): Option[B]
Optionally applies a binary operator to all elements of this iterable collection, going right to left.
Optionally applies a binary operator to all elements of this iterable collection, going right to left.
Note: will not terminate for infinite-sized collections.
Note: might return different results for different runs, unless the underlying collection type is ordered or the operator is associative and commutative.
- B
the result type of the binary operator.
- op
the binary operator.
- returns
an option value containing the result of
reduceRight(op)if this iterable collection is nonempty,Noneotherwise.
-
def
reversed: Iterable[A]
- Attributes
- protected[this]
-
def
scan[B >: A](z: B)(op: (B, B) ⇒ B): CC[B]
Computes a prefix scan of the elements of the collection.
Computes a prefix scan of the elements of the collection.
Note: The neutral element
zmay be applied more than once.- B
element type of the resulting collection
- z
neutral element for the operator
op- op
the associative operator for the scan
- returns
a new iterable collection containing the prefix scan of the elements in this iterable collection
-
def
scanLeft[B](z: B)(op: (B, A) ⇒ B): CC[B]
Produces a collection containing cumulative results of applying the operator going left to right.
Produces a collection containing cumulative results of applying the operator going left to right.
Note: will not terminate for infinite-sized collections.
Note: might return different results for different runs, unless the underlying collection type is ordered.
- B
the type of the elements in the resulting collection
- z
the initial value
- op
the binary operator applied to the intermediate result and the element
- returns
collection with intermediate results
-
def
scanRight[B](z: B)(op: (A, B) ⇒ B): CC[B]
Produces a collection containing cumulative results of applying the operator going right to left.
Produces a collection containing cumulative results of applying the operator going right to left. The head of the collection is the last cumulative result.
Note: will not terminate for infinite-sized collections.
Note: might return different results for different runs, unless the underlying collection type is ordered.
Example:
List(1, 2, 3, 4).scanRight(0)(_ + _) == List(10, 9, 7, 4, 0)
- B
the type of the elements in the resulting collection
- z
the initial value
- op
the binary operator applied to the intermediate result and the element
- returns
collection with intermediate results
-
def
size: Int
The size of this iterable collection.
The size of this iterable collection.
Note: will not terminate for infinite-sized collections.
- returns
the number of elements in this iterable collection.
-
def
slice(from: Int, until: Int): C
Selects an interval of elements.
Selects an interval of elements. The returned collection is made up of all elements
xwhich satisfy the invariant:from <= indexOf(x) < until
Note: might return different results for different runs, unless the underlying collection type is ordered.
- from
the lowest index to include from this iterable collection.
- until
the lowest index to EXCLUDE from this iterable collection.
- returns
a iterable collection containing the elements greater than or equal to index
fromextending up to (but not including) indexuntilof this iterable collection.
-
def
sliding(size: Int, step: Int): Iterator[C]
Groups elements in fixed size blocks by passing a "sliding window" over them (as opposed to partitioning them, as is done in grouped.)
Groups elements in fixed size blocks by passing a "sliding window" over them (as opposed to partitioning them, as is done in grouped.)
- size
the number of elements per group
- step
the distance between the first elements of successive groups
- returns
An iterator producing iterable collections of size
size, except the last element (which may be the only element) will be truncated if there are fewer thansizeelements remaining to be grouped.
- See also
scala.collection.Iterator, method
sliding
-
def
sliding(size: Int): Iterator[C]
Groups elements in fixed size blocks by passing a "sliding window" over them (as opposed to partitioning them, as is done in
grouped.) The "sliding window" step is set to one.Groups elements in fixed size blocks by passing a "sliding window" over them (as opposed to partitioning them, as is done in
grouped.) The "sliding window" step is set to one.- size
the number of elements per group
- returns
An iterator producing iterable collections of size
size, except the last element (which may be the only element) will be truncated if there are fewer thansizeelements remaining to be grouped.
- See also
scala.collection.Iterator, method
sliding
-
def
span(p: (A) ⇒ Boolean): (C, C)
Splits this iterable collection into a prefix/suffix pair according to a predicate.
Splits this iterable collection into a prefix/suffix pair according to a predicate.
Note:
c span pis equivalent to (but possibly more efficient than)(c takeWhile p, c dropWhile p), provided the evaluation of the predicatepdoes not cause any side-effects.Note: might return different results for different runs, unless the underlying collection type is ordered.
- p
the test predicate
- returns
a pair consisting of the longest prefix of this iterable collection whose elements all satisfy
p, and the rest of this iterable collection.
-
def
splitAt(n: Int): (C, C)
Splits this iterable collection into two at a given position.
Splits this iterable collection into two at a given position. Note:
c splitAt nis equivalent to (but possibly more efficient than)(c take n, c drop n).Note: might return different results for different runs, unless the underlying collection type is ordered.
- n
the position at which to split.
- returns
a pair of iterable collections consisting of the first
nelements of this iterable collection, and the other elements.
-
def
sum: A
[use case] Sums up the elements of this collection.
[use case]Sums up the elements of this collection.
- returns
the sum of all elements in this iterable collection of numbers of type
Int. Instead ofInt, any other typeTwith an implicitNumeric[T]implementation can be used as element type of the iterable collection and as result type ofsum. Examples of such types are:Long,Float,Double,BigInt.
Full Signaturedef sum[B >: A](implicit num: Numeric[B]): B
-
def
tail: C
The rest of the collection without its first element.
-
def
take(n: Int): C
A collection containing the first
nelements of this collection. -
def
takeRight(n: Int): C
A collection containing the last
nelements of this collection. -
def
takeWhile(p: (A) ⇒ Boolean): C
Takes longest prefix of elements that satisfy a predicate.
Takes longest prefix of elements that satisfy a predicate.
Note: might return different results for different runs, unless the underlying collection type is ordered.
- p
The predicate used to test elements.
- returns
the longest prefix of this iterable collection whose elements all satisfy the predicate
p.
-
def
to[C1](factory: Factory[A, C1]): C1
Given a collection factory
factory, convert this collection to the appropriate representation for the current element typeA.Given a collection factory
factory, convert this collection to the appropriate representation for the current element typeA. Example uses:xs.to(List) xs.to(ArrayBuffer) xs.to(BitSet) // for xs: Iterable[Int]
-
def
toArray[B >: A](implicit arg0: ClassTag[B]): Array[B]
Convert collection to array.
- def toIndexedSeq: immutable.IndexedSeq[A]
- def toList: List[A]
- def toMap[K, V](implicit ev: <:<[A, (K, V)]): immutable.Map[K, V]
- def toSeq: immutable.Seq[A]
- def toSet[B >: A]: immutable.Set[B]
-
def
toString(): String
- Definition Classes
- IterableOps → Any
- def toVector: Vector[A]
-
def
transpose[B](implicit asIterable: (A) ⇒ Iterable[B]): CC[CC[B]]
Transposes this iterable collection of iterable collections into a iterable collection of iterable collections.
Transposes this iterable collection of iterable collections into a iterable collection of iterable collections.
The resulting collection's type will be guided by the static type of iterable collection. For example:
val xs = List( Set(1, 2, 3), Set(4, 5, 6)).transpose // xs == List( // List(1, 4), // List(2, 5), // List(3, 6)) val ys = Vector( List(1, 2, 3), List(4, 5, 6)).transpose // ys == Vector( // Vector(1, 4), // Vector(2, 5), // Vector(3, 6))
- B
the type of the elements of each iterable collection.
- asIterable
an implicit conversion which asserts that the element type of this iterable collection is an
Iterable.- returns
a two-dimensional iterable collection of iterable collections which has as nth row the nth column of this iterable collection.
- Exceptions thrown
IllegalArgumentExceptionif all collections in this iterable collection are not of the same size.
-
def
unzip[A1, A2](implicit asPair: <:<[A, (A1, A2)]): (CC[A1], CC[A2])
Converts this iterable collection of pairs into two collections of the first and second half of each pair.
Converts this iterable collection of pairs into two collections of the first and second half of each pair.
val xs = Iterable( (1, "one"), (2, "two"), (3, "three")).unzip // xs == (Iterable(1, 2, 3), // Iterable(one, two, three))
- A1
the type of the first half of the element pairs
- A2
the type of the second half of the element pairs
- asPair
an implicit conversion which asserts that the element type of this iterable collection is a pair.
- returns
a pair of iterable collections, containing the first, respectively second half of each element pair of this iterable collection.
-
def
view: View[A]
A view over the elements of this collection.
-
def
withFilter(p: (A) ⇒ Boolean): collection.WithFilter[A, CC]
Creates a non-strict filter of this iterable collection.
Creates a non-strict filter of this iterable collection.
Note: the difference between
c filter pandc withFilter pis that the former creates a new collection, whereas the latter only restricts the domain of subsequentmap,flatMap,foreach, andwithFilteroperations.Note: might return different results for different runs, unless the underlying collection type is ordered.
- p
the predicate used to test elements.
- returns
an object of class
WithFilter, which supportsmap,flatMap,foreach, andwithFilteroperations. All these operations apply to those elements of this iterable collection which satisfy the predicatep.
-
def
zip[B](that: Iterable[B]): CC[(A, B)]
Returns a iterable collection formed from this iterable collection and another iterable collection by combining corresponding elements in pairs.
Returns a iterable collection formed from this iterable collection and another iterable collection by combining corresponding elements in pairs. If one of the two collections is longer than the other, its remaining elements are ignored.
- B
the type of the second half of the returned pairs
- that
The iterable providing the second half of each result pair
- returns
a new iterable collection containing pairs consisting of corresponding elements of this iterable collection and
that. The length of the returned collection is the minimum of the lengths of this iterable collection andthat.
-
def
zipWithIndex: CC[(A, Int)]
Zips this iterable collection with its indices.
Zips this iterable collection with its indices.
- returns
A new iterable collection containing pairs consisting of all elements of this iterable collection paired with their index. Indices start at
0.
List("a", "b", "c").zipWithIndex == List(("a", 0), ("b", 1), ("c", 2))
Example:
Deprecated Value Members
-
final
def
/:[B](z: B)(op: (B, A) ⇒ B): B
- Annotations
- @deprecated @inline()
- Deprecated
(Since version 2.13.0) Use foldLeft instead of /:
-
final
def
:\[B](z: B)(op: (A, B) ⇒ B): B
- Annotations
- @deprecated @inline()
- Deprecated
(Since version 2.13.0) Use foldRight instead of :\
-
def
find(p: (A) ⇒ Boolean): Option[A]
- Implicit
- This member is added by an implicit conversion from IterableOps[A, CC, C] to IterableOnceExtensionMethods[A] performed by method iterableOnceExtensionMethods in strawman.collection.IterableOnce.
- Shadowing
- This implicitly inherited member is shadowed by one or more members in this class.
To access this member you can use a type ascription:(iterableOps: IterableOnceExtensionMethods[A]).find(p)
- Definition Classes
- IterableOnceExtensionMethods
- Annotations
- @deprecated
- Deprecated
(Since version 2.13.0) Use .iterator().find instead of .find on IterableOnce
-
def
foreach[U](f: (A) ⇒ U): Unit
- Implicit
- This member is added by an implicit conversion from IterableOps[A, CC, C] to IterableOnceExtensionMethods[A] performed by method iterableOnceExtensionMethods in strawman.collection.IterableOnce.
- Shadowing
- This implicitly inherited member is shadowed by one or more members in this class.
To access this member you can use a type ascription:(iterableOps: IterableOnceExtensionMethods[A]).foreach(f)
- Definition Classes
- IterableOnceExtensionMethods
- Annotations
- @deprecated @inline()
- Deprecated
(Since version 2.13.0) Use .iterator().foreach(...) instead of .foreach(...) on IterableOnce
-
final
def
hasDefiniteSize: Boolean
- Annotations
- @deprecated @inline()
- Deprecated
(Since version 2.13.0) Use .knownSize >=0 instead of .hasDefiniteSize
-
def
isEmpty: Boolean
- Implicit
- This member is added by an implicit conversion from IterableOps[A, CC, C] to IterableOnceExtensionMethods[A] performed by method iterableOnceExtensionMethods in strawman.collection.IterableOnce.
- Shadowing
- This implicitly inherited member is shadowed by one or more members in this class.
To access this member you can use a type ascription:(iterableOps: IterableOnceExtensionMethods[A]).isEmpty
- Definition Classes
- IterableOnceExtensionMethods
- Annotations
- @deprecated
- Deprecated
(Since version 2.13.0) Use .iterator().isEmpty instead of .isEmpty on IterableOnce
-
def
mkString: String
- Implicit
- This member is added by an implicit conversion from IterableOps[A, CC, C] to IterableOnceExtensionMethods[A] performed by method iterableOnceExtensionMethods in strawman.collection.IterableOnce.
- Shadowing
- This implicitly inherited member is shadowed by one or more members in this class.
To access this member you can use a type ascription:(iterableOps: IterableOnceExtensionMethods[A]).mkString
- Definition Classes
- IterableOnceExtensionMethods
- Annotations
- @deprecated
- Deprecated
(Since version 2.13.0) Use .iterator().mkString instead of .mkString on IterableOnce
-
def
mkString(sep: String): String
- Implicit
- This member is added by an implicit conversion from IterableOps[A, CC, C] to IterableOnceExtensionMethods[A] performed by method iterableOnceExtensionMethods in strawman.collection.IterableOnce.
- Shadowing
- This implicitly inherited member is shadowed by one or more members in this class.
To access this member you can use a type ascription:(iterableOps: IterableOnceExtensionMethods[A]).mkString(sep)
- Definition Classes
- IterableOnceExtensionMethods
- Annotations
- @deprecated
- Deprecated
(Since version 2.13.0) Use .iterator().mkString instead of .mkString on IterableOnce
-
def
mkString(start: String, sep: String, end: String): String
- Implicit
- This member is added by an implicit conversion from IterableOps[A, CC, C] to IterableOnceExtensionMethods[A] performed by method iterableOnceExtensionMethods in strawman.collection.IterableOnce.
- Shadowing
- This implicitly inherited member is shadowed by one or more members in this class.
To access this member you can use a type ascription:(iterableOps: IterableOnceExtensionMethods[A]).mkString(start, sep, end)
- Definition Classes
- IterableOnceExtensionMethods
- Annotations
- @deprecated
- Deprecated
(Since version 2.13.0) Use .iterator().mkString instead of .mkString on IterableOnce
-
final
def
stringPrefix: String
- Annotations
- @deprecated @inline()
- Deprecated
(Since version 2.13.0) Use className instead of stringPrefix
-
def
toArray[B >: A](implicit arg0: ClassTag[B]): Array[B]
- Implicit
- This member is added by an implicit conversion from IterableOps[A, CC, C] to IterableOnceExtensionMethods[A] performed by method iterableOnceExtensionMethods in strawman.collection.IterableOnce.
- Shadowing
- This implicitly inherited member is shadowed by one or more members in this class.
To access this member you can use a type ascription:(iterableOps: IterableOnceExtensionMethods[A]).toArray(arg0)
- Definition Classes
- IterableOnceExtensionMethods
- Annotations
- @deprecated
- Deprecated
(Since version 2.13.0) Use ArrayBuffer.from(it).toArray
-
def
toBuffer[B >: A]: Buffer[B]
- Implicit
- This member is added by an implicit conversion from IterableOps[A, CC, C] to IterableOnceExtensionMethods[A] performed by method iterableOnceExtensionMethods in strawman.collection.IterableOnce.
- Definition Classes
- IterableOnceExtensionMethods
- Annotations
- @deprecated
- Deprecated
(Since version 2.13.0) Use ArrayBuffer.from(it) instead of it.toBuffer
-
def
toList[B >: A]: List[B]
- Implicit
- This member is added by an implicit conversion from IterableOps[A, CC, C] to IterableOnceExtensionMethods[A] performed by method iterableOnceExtensionMethods in strawman.collection.IterableOnce.
- Shadowing
- This implicitly inherited member is shadowed by one or more members in this class.
To access this member you can use a type ascription:(iterableOps: IterableOnceExtensionMethods[A]).toList
- Definition Classes
- IterableOnceExtensionMethods
- Annotations
- @deprecated
- Deprecated
(Since version 2.13.0) Use List.from(it) instead of it.toList