@@ -761,20 +761,19 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal {
761
761
true
762
762
}
763
763
764
- /** Applies a binary operator to a start value and all elements of this array,
765
- * going left to right.
766
- *
767
- * @param z the start value.
768
- * @param op the binary operator.
769
- * @tparam B the result type of the binary operator.
770
- * @return the result of inserting `op` between consecutive elements of this array,
771
- * going left to right with the start value `z` on the left:
772
- * {{{
773
- * op(...op(z, x_1), x_2, ..., x_n)
774
- * }}}
775
- * where `x,,1,,, ..., x,,n,,` are the elements of this array.
776
- * Returns `z` if this array is empty.
777
- */
764
+ /** Applies the given binary operator `op` to the given initial value `z` and
765
+ * all elements of this array, going left to right. Returns the initial value
766
+ * if this array is empty.
767
+ *
768
+ * If `x,,1,,`, `x,,2,,`, ..., `x,,n,,` are the elements of this array, the
769
+ * result is `op( op( ... op( op(z, x,,1,,), x,,2,,) ... ), x,,n,,)`.
770
+ *
771
+ * @param z An initial value.
772
+ * @param op A binary operator.
773
+ * @tparam B The result type of the binary operator.
774
+ * @return The result of applying `op` to `z` and all elements of this array,
775
+ * going left to right. Returns `z` if this array is empty.
776
+ */
778
777
def foldLeft [B ](z : B )(op : (B , A ) => B ): B = {
779
778
def f [@ specialized(Specializable .Everything ) T ](xs : Array [T ], op : (Any , Any ) => Any , z : Any ): Any = {
780
779
val length = xs.length
@@ -867,20 +866,20 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal {
867
866
res
868
867
}
869
868
870
- /** Applies a binary operator to all elements of this array and a start value,
871
- * going right to left.
872
- *
873
- * @param z the start value.
874
- * @param op the binary operator.
875
- * @tparam B the result type of the binary operator .
876
- * @return the result of inserting `op` between consecutive elements of this array,
877
- * going right to left with the start value `z` on the right:
878
- * {{{
879
- * op(x_1, op(x_2, ... op(x_n, z)...))
880
- * }}}
881
- * where `x,,1,,, ..., x,,n,,` are the elements of this array.
882
- * Returns `z` if this array is empty.
883
- */
869
+ /** Applies the given binary operator `op` to all elements of this array and
870
+ * the given initial value `z`, going right to left. Returns the initial
871
+ * value if this array is empty.
872
+ *
873
+ * If `x,,1,,`, `x,,2,,`, ..., `x,,n,,` are the elements of this array, the
874
+ * result is `op(x,,1,,, op(x,,2,,, op( ... op(x,,n,,, z) ... )))` .
875
+ *
876
+ * @param z An initial value.
877
+ * @param op A binary operator.
878
+ * @tparam B The result type of the binary operator.
879
+ * @return The result of applying `op` to all elements of this array
880
+ * and `z`, going right to left. Returns `z` if this array
881
+ * is empty.
882
+ */
884
883
def foldRight [B ](z : B )(op : (A , B ) => B ): B = {
885
884
def f [@ specialized(Specializable .Everything ) T ](xs : Array [T ], op : (Any , Any ) => Any , z : Any ): Any = {
886
885
var v = z
@@ -907,15 +906,17 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal {
907
906
908
907
}
909
908
910
- /** Folds the elements of this array using the specified associative binary operator.
911
- *
912
- * @tparam A1 a type parameter for the binary operator, a supertype of `A`.
913
- * @param z a neutral element for the fold operation; may be added to the result
914
- * an arbitrary number of times, and must not change the result (e.g., `Nil` for list concatenation,
915
- * 0 for addition, or 1 for multiplication).
916
- * @param op a binary operator that must be associative.
917
- * @return the result of applying the fold operator `op` between all the elements, or `z` if this array is empty.
918
- */
909
+ /** Alias for [[foldLeft ]].
910
+ *
911
+ * The type parameter is more restrictive than for `foldLeft` to be
912
+ * consistent with [[IterableOnceOps.fold ]].
913
+ *
914
+ * @tparam A1 The type parameter for the binary operator, a supertype of `A`.
915
+ * @param z An initial value.
916
+ * @param op A binary operator.
917
+ * @return The result of applying `op` to `z` and all elements of this array,
918
+ * going left to right. Returns `z` if this string is empty.
919
+ */
919
920
def fold [A1 >: A ](z : A1 )(op : (A1 , A1 ) => A1 ): A1 = foldLeft(z)(op)
920
921
921
922
/** Builds a new array by applying a function to all elements of this array.
0 commit comments