You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _overviews/collections-2.13/trait-iterable.md
+7-6Lines changed: 7 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,7 @@ Collection classes that implement `Iterable` just need to define this method; al
22
22
23
23
***Addition**, `concat`, which appends two collections together, or appends all elements of an iterator to a collection.
24
24
***Map** operations `map`, `flatMap`, and `collect`, which produce a new collection by applying some function to collection elements.
25
-
***Conversions**`toArray`, `toList`, `toIterable`, `toSeq`, `toIndexedSeq`, `toStream`, `toSet`, `toMap`, which turn an `Iterable` collection into something more specific. All these conversions return their receiver argument unchanged if the run-time type of the collection already matches the demanded collection type. For instance, applying `toList` to a list will yield the list itself.
25
+
***Conversions**`to`, `toList`, `toVector`, `toMap`, `toSet`, `toSeq`, `toIndexedSeq`, `toBuffer`, `toArray`which turn an `Iterable` collection into something more specific. If the destination is a mutable collection(`to(collection.mutable.X)`, `toArray`, `toBuffer`), a new collection is created by copying the original elements. All these conversions return their receiver argument unchanged if the run-time type of the collection already matches the demanded collection type. For instance, applying `toList` to a list will yield the list itself.
26
26
***Copying operations**`copyToArray`. As its name implies, this copies collection elements to an array.
27
27
***Size info** operations `isEmpty`, `nonEmpty`, `size`, `knownSize`, `sizeIs`. The number of elements of a collections can require a traversal in some cases (e.g. `List`). In other cases the collection can have an infinite number of elements (e.g. `LazyList.from(1)`).
28
28
***Element retrieval** operations `head`, `last`, `headOption`, `lastOption`, and `find`. These select the first or last element of a collection, or else the first element matching a condition. Note, however, that not all collections have a well-defined meaning of what "first" and "last" means. For instance, a hash set might store elements according to their hash keys, which might change from run to run. In that case, the "first" element of a hash set could also be different for every run of a program. A collection is _ordered_ if it always yields its elements in the same order. Most collections are ordered, but some (_e.g._ hash sets) are not-- dropping the ordering gives a little bit of extra efficiency. Ordering is often essential to give reproducible tests and to help in debugging. That's why Scala collections give ordered alternatives for all collection types. For instance, the ordered alternative for `HashSet` is `LinkedHashSet`.
@@ -70,14 +70,15 @@ Two more methods exist in `Iterable` that return iterators: `grouped` and `slidi
70
70
|`xs flatMap f`|The collection obtained from applying the collection-valued function `f` to every element in `xs` and concatenating the results.|
71
71
|`xs collect f`|The collection obtained from applying the partial function `f` to every element in `xs` for which it is defined and collecting the results.|
72
72
|**Conversions:**||
73
-
|`xs.toArray`|Converts the collection to an array. |
73
+
|`xs.to(SortedSet)`| Generic conversion operation that takes a collection factory as parameter.|
74
74
|`xs.toList`|Converts the collection to a list. |
75
-
|`xs.toIterable`|Converts the collection to an iterable. |
75
+
|`xs.toVector`|Converts the collection to a vector. |
76
+
|`xs.toMap`|Converts the collection of key/value pairs to a map. If the collection does not have pairs as elements, calling this operation results in a static type error.|
77
+
|`xs.toSet`|Converts the collection to a set. |
76
78
|`xs.toSeq`|Converts the collection to a sequence. |
77
79
|`xs.toIndexedSeq`|Converts the collection to an indexed sequence. |
78
-
|`xs.toSet`|Converts the collection to a set. |
79
-
|`xs.toMap`|Converts the collection of key/value pairs to a map. If the collection does not have pairs as elements, calling this operation results in a static type error.|
80
-
|`xs.to(SortedSet)`| Generic conversion operation that takes a collection factory as parameter. |
80
+
|`xs.toBuffer`|Converts the collection to a buffer. |
81
+
|`xs.toArray`|Converts the collection to an array. |
81
82
|**Copying:**||
82
83
|`xs copyToArray(arr, s, n)`|Copies at most `n` elements of the collection to array `arr` starting at index `s`. The last two arguments are optional.|
0 commit comments