@@ -42,7 +42,13 @@ import scala.runtime.{AbstractFunction1, AbstractFunction2}
42
42
* @define coll collection
43
43
*/
44
44
trait IterableOnce [+ A ] extends Any {
45
- /** Iterator can be used only once */
45
+
46
+ /** An [[scala.collection.Iterator ]] over the elements of this $coll.
47
+ *
48
+ * If an `IterableOnce` object is in fact an [[scala.collection.Iterator ]], this method always returns itself,
49
+ * in its current state, but if it is an [[scala.collection.Iterable ]], this method always returns a new
50
+ * [[scala.collection.Iterator ]].
51
+ */
46
52
def iterator : Iterator [A ]
47
53
48
54
/** Returns a [[scala.collection.Stepper ]] for the elements of this collection.
@@ -76,7 +82,7 @@ trait IterableOnce[+A] extends Any {
76
82
s.asInstanceOf [S ]
77
83
}
78
84
79
- /** @return The number of elements in this $coll, if it can be cheaply computed,
85
+ /** The number of elements in this $coll, if it can be cheaply computed,
80
86
* -1 otherwise. Cheaply usually means: Not requiring a collection traversal.
81
87
*/
82
88
def knownSize : Int = - 1
@@ -347,7 +353,7 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
347
353
*/
348
354
def filterNot (pred : A => Boolean ): C
349
355
350
- /** Selects the first ''n'' elements.
356
+ /** Selects the first `n` elements.
351
357
* $orderDependent
352
358
* @param n the number of elements to take from this $coll.
353
359
* @return a $coll consisting only of the first `n` elements of this $coll,
@@ -356,7 +362,7 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
356
362
*/
357
363
def take (n : Int ): C
358
364
359
- /** Takes longest prefix of elements that satisfy a predicate.
365
+ /** Selects the longest prefix of elements that satisfy a predicate.
360
366
*
361
367
* The matching prefix starts with the first element of this $coll,
362
368
* and the element following the prefix is the first element that
@@ -382,7 +388,7 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
382
388
*/
383
389
def takeWhile (p : A => Boolean ): C
384
390
385
- /** Selects all elements except first ''n'' ones.
391
+ /** Selects all elements except the first `n` ones.
386
392
* $orderDependent
387
393
* @param n the number of elements to drop from this $coll.
388
394
* @return a $coll consisting of all elements of this $coll except the first `n` ones, or else the
@@ -391,7 +397,7 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
391
397
*/
392
398
def drop (n : Int ): C
393
399
394
- /** Drops longest prefix of elements that satisfy a predicate.
400
+ /** Selects all elements except the longest prefix that satisfies a predicate.
395
401
*
396
402
* The matching prefix starts with the first element of this $coll,
397
403
* and the element following the prefix is the first element that
@@ -605,8 +611,8 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
605
611
*/
606
612
def isTraversableAgain : Boolean = false
607
613
608
- /** Apply `f` to each element for its side effects
609
- * Note: [U] parameter needed to help scalac's type inference.
614
+ /** Applies `f` to each element for its side effects.
615
+ * Note: `U` parameter needed to help scalac's type inference.
610
616
*/
611
617
def foreach [U ](f : A => U ): Unit = {
612
618
val it = iterator
@@ -907,7 +913,7 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
907
913
@ deprecated(" Use `dest ++= coll` instead" , " 2.13.0" )
908
914
@ inline final def copyToBuffer [B >: A ](dest : mutable.Buffer [B ]): Unit = dest ++= this
909
915
910
- /** Copy elements to an array, returning the number of elements written.
916
+ /** Copies elements to an array, returning the number of elements written.
911
917
*
912
918
* Fills the given array `xs` starting at index `start` with values of this $coll.
913
919
*
@@ -923,7 +929,7 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
923
929
@ deprecatedOverriding(" This should always forward to the 3-arg version of this method" , since = " 2.13.4" )
924
930
def copyToArray [B >: A ](xs : Array [B ]): Int = copyToArray(xs, 0 , Int .MaxValue )
925
931
926
- /** Copy elements to an array, returning the number of elements written.
932
+ /** Copies elements to an array, returning the number of elements written.
927
933
*
928
934
* Fills the given array `xs` starting at index `start` with values of this $coll.
929
935
*
@@ -1067,15 +1073,15 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
1067
1073
case _ => Some (reduceLeft(ord.max))
1068
1074
}
1069
1075
1070
- /** Finds the first element which yields the largest value measured by function f .
1076
+ /** Finds the first element which yields the largest value measured by function `f` .
1071
1077
*
1072
1078
* $willNotTerminateInf
1073
1079
*
1074
1080
* @param cmp An ordering to be used for comparing elements.
1075
- * @tparam B The result type of the function f .
1081
+ * @tparam B The result type of the function `f` .
1076
1082
* @param f The measuring function.
1077
1083
* @throws UnsupportedOperationException if this $coll is empty.
1078
- * @return the first element of this $coll with the largest value measured by function f
1084
+ * @return the first element of this $coll with the largest value measured by function `f`
1079
1085
* with respect to the ordering `cmp`.
1080
1086
*/
1081
1087
def maxBy [B ](f : A => B )(implicit ord : Ordering [B ]): A =
@@ -1107,31 +1113,31 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
1107
1113
}
1108
1114
}
1109
1115
1110
- /** Finds the first element which yields the largest value measured by function f .
1116
+ /** Finds the first element which yields the largest value measured by function `f` .
1111
1117
*
1112
1118
* $willNotTerminateInf
1113
1119
*
1114
1120
* @param cmp An ordering to be used for comparing elements.
1115
- * @tparam B The result type of the function f .
1121
+ * @tparam B The result type of the function `f` .
1116
1122
* @param f The measuring function.
1117
1123
* @return an option value containing the first element of this $coll with the
1118
- * largest value measured by function f with respect to the ordering `cmp`.
1124
+ * largest value measured by function `f` with respect to the ordering `cmp`.
1119
1125
*/
1120
1126
def maxByOption [B ](f : A => B )(implicit ord : Ordering [B ]): Option [A ] =
1121
1127
knownSize match {
1122
1128
case 0 => None
1123
1129
case _ => foldLeft(new Maximized [A , B ](" maxBy" )(f)(ord.gt))((m, a) => m(m, a)).toOption
1124
1130
}
1125
1131
1126
- /** Finds the first element which yields the smallest value measured by function f .
1132
+ /** Finds the first element which yields the smallest value measured by function `f` .
1127
1133
*
1128
1134
* $willNotTerminateInf
1129
1135
*
1130
1136
* @param cmp An ordering to be used for comparing elements.
1131
- * @tparam B The result type of the function f .
1137
+ * @tparam B The result type of the function `f` .
1132
1138
* @param f The measuring function.
1133
1139
* @throws UnsupportedOperationException if this $coll is empty.
1134
- * @return the first element of this $coll with the smallest value measured by function f
1140
+ * @return the first element of this $coll with the smallest value measured by function `f`
1135
1141
* with respect to the ordering `cmp`.
1136
1142
*/
1137
1143
def minBy [B ](f : A => B )(implicit ord : Ordering [B ]): A =
@@ -1140,15 +1146,15 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
1140
1146
case _ => foldLeft(new Maximized [A , B ](" minBy" )(f)(ord.lt))((m, a) => m(m, a)).result
1141
1147
}
1142
1148
1143
- /** Finds the first element which yields the smallest value measured by function f .
1149
+ /** Finds the first element which yields the smallest value measured by function `f` .
1144
1150
*
1145
1151
* $willNotTerminateInf
1146
1152
*
1147
1153
* @param cmp An ordering to be used for comparing elements.
1148
- * @tparam B The result type of the function f .
1154
+ * @tparam B The result type of the function `f` .
1149
1155
* @param f The measuring function.
1150
1156
* @return an option value containing the first element of this $coll
1151
- * with the smallest value measured by function f
1157
+ * with the smallest value measured by function `f`
1152
1158
* with respect to the ordering `cmp`.
1153
1159
*/
1154
1160
def minByOption [B ](f : A => B )(implicit ord : Ordering [B ]): Option [A ] =
@@ -1335,7 +1341,7 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
1335
1341
*/
1336
1342
@ inline final def addString (b : StringBuilder ): b.type = addString(b, " " )
1337
1343
1338
- /** Given a collection factory `factory`, convert this collection to the appropriate
1344
+ /** Given a collection factory `factory`, converts this $coll to the appropriate
1339
1345
* representation for the current element type `A`. Example uses:
1340
1346
*
1341
1347
* {{{
@@ -1349,29 +1355,61 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
1349
1355
@ deprecated(" Use .iterator instead of .toIterator" , " 2.13.0" )
1350
1356
@ `inline` final def toIterator : Iterator [A ] = iterator
1351
1357
1358
+ /** Converts this $coll to a `List`.
1359
+ *
1360
+ * @return This $coll as a `List[A]`.
1361
+ */
1352
1362
def toList : immutable.List [A ] = immutable.List .from(this )
1353
1363
1364
+ /** Converts this $coll to a `Vector`.
1365
+ *
1366
+ * @return This $coll as a `Vector[A]`.
1367
+ */
1354
1368
def toVector : immutable.Vector [A ] = immutable.Vector .from(this )
1355
1369
1370
+ /** Converts this $coll to a `Map`, given an implicit coercion from the $coll's type to a key-value tuple.
1371
+ *
1372
+ * @tparam K The key type for the resulting map.
1373
+ * @tparam V The value type for the resulting map.
1374
+ * @param ev An implicit coercion from `A` to `[K, V]`.
1375
+ * @return This $coll as a `Map[K, V]`.
1376
+ */
1356
1377
def toMap [K , V ](implicit ev : A <:< (K , V )): immutable.Map [K , V ] =
1357
1378
immutable.Map .from(this .asInstanceOf [IterableOnce [(K , V )]])
1358
1379
1380
+ /** Converts this $coll to a `Set`.
1381
+ *
1382
+ * @tparam B The type of elements of the result, a supertype of `A`.
1383
+ * @return This $coll as a `Set[B]`.
1384
+ */
1359
1385
def toSet [B >: A ]: immutable.Set [B ] = immutable.Set .from(this )
1360
1386
1361
- /** @return This collection as a `Seq[A]`. This is equivalent to `to(Seq)` but might be faster.
1387
+ /** @return This $coll as a `Seq[A]`. This is equivalent to `to(Seq)` but might be faster.
1362
1388
*/
1363
1389
def toSeq : immutable.Seq [A ] = immutable.Seq .from(this )
1364
1390
1391
+ /** Converts this $coll to an `IndexedSeq`.
1392
+ *
1393
+ * @return This $coll as an `IndexedSeq[A]`.
1394
+ */
1365
1395
def toIndexedSeq : immutable.IndexedSeq [A ] = immutable.IndexedSeq .from(this )
1366
1396
1367
1397
@ deprecated(" Use .to(LazyList) instead of .toStream" , " 2.13.0" )
1368
1398
@ inline final def toStream : immutable.Stream [A ] = to(immutable.Stream )
1369
1399
1400
+ /** Converts this $coll to a `Buffer`.
1401
+ *
1402
+ * @tparam B The type of elements of the result, a supertype of `A`.
1403
+ * @return This $coll as a `Buffer[B]`.
1404
+ */
1370
1405
@ inline final def toBuffer [B >: A ]: mutable.Buffer [B ] = mutable.Buffer .from(this )
1371
1406
1372
- /** Convert collection to array .
1407
+ /** Converts this $coll to an `Array` .
1373
1408
*
1374
1409
* Implementation note: DO NOT call [[Array.from ]] from this method.
1410
+ *
1411
+ * @tparam B The type of elements of the result, a supertype of `A`.
1412
+ * @return This $coll as an `Array[B]`.
1375
1413
*/
1376
1414
def toArray [B >: A : ClassTag ]: Array [B ] =
1377
1415
if (knownSize >= 0 ) {
0 commit comments