@@ -3,7 +3,7 @@ package collection
3
3
4
4
import scala .language .{higherKinds , implicitConversions }
5
5
import scala .annotation .unchecked .uncheckedVariance
6
- import scala .math .{Ordering , Numeric }
6
+ import scala .math .{Numeric , Ordering }
7
7
import scala .reflect .ClassTag
8
8
import scala .collection .mutable .StringBuilder
9
9
@@ -357,6 +357,16 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
357
357
*/
358
358
def knownSize : Int = - 1
359
359
360
+ @ deprecated(" Use .knownSize >=0 instead of .hasDefiniteSize" , " 2.13.0" )
361
+ @ `inline` final def hasDefiniteSize = knownSize >= 0
362
+
363
+ /** Tests whether this $coll can be repeatedly traversed. Always
364
+ * true for Iterables and false for Iterators unless overridden.
365
+ *
366
+ * @return `true` if it is repeatedly traversable, `false` otherwise.
367
+ */
368
+ def isTraversableAgain : Boolean = false
369
+
360
370
/** Apply `f` to each element for its side effects
361
371
* Note: [U] parameter needed to help scalac's type inference.
362
372
*/
@@ -627,6 +637,22 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
627
637
@ deprecated(" Use `dest ++= coll` instead" , " 2.13.0" )
628
638
@ inline final def copyToBuffer [B >: A ](dest : mutable.Buffer [B ]): Unit = dest ++= this
629
639
640
+ /** Copy elements to an array.
641
+ *
642
+ * Fills the given array `xs` starting at index `start` with values of this $coll.
643
+ *
644
+ * Copying will stop once either all the elements of this $coll have been copied,
645
+ * or the end of the array is reached.
646
+ *
647
+ * @param xs the array to fill.
648
+ * @tparam B the type of the elements of the array.
649
+ *
650
+ * @usecase def copyToArray(xs: Array[A]): Unit
651
+ *
652
+ * $willNotTerminateInf
653
+ */
654
+ def copyToArray [B >: A ](xs : Array [B ]): xs.type = copyToArray(xs, 0 )
655
+
630
656
/** Copy elements to an array.
631
657
*
632
658
* Fills the given array `xs` starting at index `start` with values of this $coll.
@@ -642,7 +668,8 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
642
668
*
643
669
* $willNotTerminateInf
644
670
*/
645
- def copyToArray [B >: A ](xs : Array [B ], start : Int = 0 ): xs.type = {
671
+
672
+ def copyToArray [B >: A ](xs : Array [B ], start : Int ): xs.type = {
646
673
val xsLen = xs.length
647
674
val it = iterator
648
675
var i = start
@@ -914,7 +941,9 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
914
941
def collectFirst [B ](pf : PartialFunction [A , B ]): Option [B ] = {
915
942
// Presumably the fastest way to get in and out of a partial function is for a sentinel function to return itself
916
943
// (Tested to be lower-overhead than runWith. Would be better yet to not need to (formally) allocate it)
917
- val sentinel : scala.Function1 [A , Any ] = new scala.runtime.AbstractFunction1 [A , Any ]{ def apply (a : A ) = this }
944
+ val sentinel : scala.Function1 [A , Any ] = new scala.runtime.AbstractFunction1 [A , Any ] {
945
+ def apply (a : A ) = this
946
+ }
918
947
val it = iterator
919
948
while (it.hasNext) {
920
949
val x = pf.applyOrElse(it.next(), sentinel)
@@ -923,6 +952,30 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
923
952
None
924
953
}
925
954
955
+ @ deprecated(" `aggregate` is not relevant for sequential collections. Use `foldLeft(z)(seqop)` instead." , " 2.13.0" )
956
+ def aggregate [B ](z : => B )(seqop : (B , A ) => B , combop : (B , B ) => B ): B = foldLeft(z)(seqop)
957
+
958
+ /** Tests whether every element of this collection's iterator relates to the
959
+ * corresponding element of another collection by satisfying a test predicate.
960
+ *
961
+ * @param that the other collection
962
+ * @param p the test predicate, which relates elements from both collections
963
+ * @tparam B the type of the elements of `that`
964
+ * @return `true` if both collections have the same length and
965
+ * `p(x, y)` is `true` for all corresponding elements `x` of this iterator
966
+ * and `y` of `that`, otherwise `false`
967
+ */
968
+ def corresponds [B ](that : IterableOnce [B ])(p : (A , B ) => Boolean ): Boolean = {
969
+ val a = iterator
970
+ val b = that.iterator
971
+
972
+ while (a.hasNext && b.hasNext) {
973
+ if (! p(a.next(), b.next())) return false
974
+ }
975
+
976
+ a.hasNext == b.hasNext
977
+ }
978
+
926
979
/** Displays all elements of this $coll in a string using start, end, and
927
980
* separator strings.
928
981
*
0 commit comments