Skip to content

Commit e5a6cbf

Browse files
authored
Added note about copying elements during conversion (#1643)
scala/bug#11872 In addition, the method introduction was modified to the latest method list.
1 parent 6b36bbf commit e5a6cbf

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

_overviews/collections-2.13/trait-iterable.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Collection classes that implement `Iterable` just need to define this method; al
2222

2323
* **Addition**, `concat`, which appends two collections together, or appends all elements of an iterator to a collection.
2424
* **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.
2626
* **Copying operations** `copyToArray`. As its name implies, this copies collection elements to an array.
2727
* **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)`).
2828
* **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
7070
| `xs flatMap f` |The collection obtained from applying the collection-valued function `f` to every element in `xs` and concatenating the results.|
7171
| `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.|
7272
| **Conversions:** | |
73-
| `xs.toArray` |Converts the collection to an array. |
73+
| `xs.to(SortedSet)` | Generic conversion operation that takes a collection factory as parameter. |
7474
| `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. |
7678
| `xs.toSeq` |Converts the collection to a sequence. |
7779
| `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. |
8182
| **Copying:** | |
8283
| `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.|
8384
| **Size info:** | |

0 commit comments

Comments
 (0)