diff options
author | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2011-04-19 16:57:44 +0000 |
---|---|---|
committer | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2011-04-19 16:57:44 +0000 |
commit | e6efa7b11f44d2e405d02c563b710023b3ef3e8a (patch) | |
tree | 21b815869f52a52f83bf774f770d2244f9eb9e0f | |
parent | bf53d9f48e0e04e6f7fc3b84d3066437c0cc2fc6 (diff) | |
download | scala-e6efa7b11f44d2e405d02c563b710023b3ef3e8a.tar.gz scala-e6efa7b11f44d2e405d02c563b710023b3ef3e8a.tar.bz2 scala-e6efa7b11f44d2e405d02c563b710023b3ef3e8a.zip |
Removed GenTravOnceLike and TravOnceLike, put t...
Removed GenTravOnceLike and TravOnceLike, put their functionality to
GenTravOnce and TravOnce. Remove immutable Gen* traits. Removing mutable
Gen* traits.
No review.
36 files changed, 875 insertions, 927 deletions
diff --git a/src/library/scala/collection/GenTraversableLike.scala b/src/library/scala/collection/GenTraversableLike.scala index e415e47ce8..44aae3053f 100644 --- a/src/library/scala/collection/GenTraversableLike.scala +++ b/src/library/scala/collection/GenTraversableLike.scala @@ -50,7 +50,7 @@ import annotation.migration * @author Aleksandar Prokopec * @since 2.9 */ -private[collection] trait GenTraversableLike[+A, +Repr] extends GenTraversableOnceLike[A] with Parallelizable[A, parallel.ParIterable[A]] { +private[collection] trait GenTraversableLike[+A, +Repr] extends GenTraversableOnce[A] with Parallelizable[A, parallel.ParIterable[A]] { def repr: Repr diff --git a/src/library/scala/collection/GenTraversableOnce.scala b/src/library/scala/collection/GenTraversableOnce.scala index 41dfa96e93..053a6d211a 100644 --- a/src/library/scala/collection/GenTraversableOnce.scala +++ b/src/library/scala/collection/GenTraversableOnce.scala @@ -8,13 +8,503 @@ package scala.collection -/** A trait for all traversable-once objects which may be +/** A template trait for all traversable-once objects which may be * traversed in parallel. * + * Methods in this trait are either abstract or can be implemented in terms + * of other methods. + * + * @define Coll GenTraversableOnce + * @define coll collection or iterator + * @define possiblyparinfo + * This trait may possibly have operations implemented in parallel. + * @define undefinedorder + * The order in which operations are performed on elements is unspecified and may be nondeterministic. + * @define orderDependent + * + * Note: might return different results for different runs, unless the underlying collection type is ordered. + * @define orderDependentFold + * + * Note: might return different results for different runs, unless the + * underlying collection type is ordered or the operator is associative + * and commutative. + * @define mayNotTerminateInf + * + * Note: may not terminate for infinite-sized collections. + * @define willNotTerminateInf + * + * Note: will not terminate for infinite-sized collections. + * * @author Martin Odersky * @author Aleksandar Prokopec * @since 2.9 */ -trait GenTraversableOnce[+A] extends GenTraversableOnceLike[A] { +private[collection] trait GenTraversableOnce[+A] { + + def foreach[U](f: A => U): Unit + + def hasDefiniteSize: Boolean + def seq: TraversableOnce[A] + + /** The size of this $coll. + * + * $willNotTerminateInf + * + * @return the number of elements in this $coll. + */ + def size: Int + + /** Tests whether the $coll is empty. + * + * @return `true` if the $coll contains no elements, `false` otherwise. + */ + def isEmpty: Boolean + + /** Tests whether the $coll is not empty. + * + * @return `true` if the $coll contains at least one element, `false` otherwise. + */ + def nonEmpty: Boolean + + /** Tests whether this $coll can be repeatedly traversed. Always + * true for Traversables and false for Iterators unless overridden. + * + * @return `true` if it is repeatedly traversable, `false` otherwise. + */ + def isTraversableAgain: Boolean + + /** Reduces the elements of this sequence using the specified associative binary operator. + * + * $undefinedorder + * + * Note this method has a different signature than the `reduceLeft` + * and `reduceRight` methods of the trait `Traversable`. + * The result of reducing may only be a supertype of this parallel collection's + * type parameter `T`. + * + * @tparam U A type parameter for the binary operator, a supertype of `T`. + * @param op A binary operator that must be associative. + * @return The result of applying reduce operator `op` between all the elements if the collection is nonempty. + * @throws UnsupportedOperationException + * if this $coll is empty. + */ + def reduce[A1 >: A](op: (A1, A1) => A1): A1 + + /** Optionally reduces the elements of this sequence using the specified associative binary operator. + * + * $undefinedorder + * + * Note this method has a different signature than the `reduceLeftOption` + * and `reduceRightOption` methods of the trait `Traversable`. + * The result of reducing may only be a supertype of this parallel collection's + * type parameter `T`. + * + * @tparam U A type parameter for the binary operator, a supertype of `T`. + * @param op A binary operator that must be associative. + * @return An option value containing result of applying reduce operator `op` between all + * the elements if the collection is nonempty, and `None` otherwise. + */ + def reduceOption[A1 >: A](op: (A1, A1) => A1): Option[A1] + + /** Folds the elements of this sequence using the specified associative binary operator. + * The order in which the elements are reduced is unspecified and may be nondeterministic. + * + * Note this method has a different signature than the `foldLeft` + * and `foldRight` methods of the trait `Traversable`. + * The result of folding may only be a supertype of this parallel collection's + * type parameter `T`. + * + * @tparam U a type parameter for the binary operator, a supertype of `T`. + * @param z a neutral element for the fold operation, it may be added to the result + * an arbitrary number of times, not changing the result (e.g. `Nil` for list concatenation, + * 0 for addition, or 1 for multiplication) + * @param op a binary operator that must be associative + * @return the result of applying fold operator `op` between all the elements and `z` + */ + def fold[A1 >: A](z: A1)(op: (A1, A1) => A1): A1 + + /** A syntactic sugar for out of order folding. See `fold`. */ + def /:\[A1 >: A](z: A1)(op: (A1, A1) => A1): A1 = fold(z)(op) + + /** Applies a binary operator to a start value and all elements of this $coll, + * going left to right. + * + * Note: `/:` is alternate syntax for `foldLeft`; `z /: xs` is the same as + * `xs foldLeft z`. + * $willNotTerminateInf + * $orderDependentFold + * + * @param z the start value. + * @param op the binary operator. + * @tparam B the result type of the binary operator. + * @return the result of inserting `op` between consecutive elements of this $coll, + * going left to right with the start value `z` on the left: + * {{{ + * op(...op(op(z, x,,1,,), x,,2,,), ..., x,,n,,) + * }}} + * where `x,,1,,, ..., x,,n,,` are the elements of this $coll. + */ + def /:[B](z: B)(op: (B, A) => B): B + + /** Applies a binary operator to all elements of this $coll and a start value, + * going right to left. + * + * Note: `:\` is alternate syntax for `foldRight`; `xs :\ z` is the same as + * `xs foldRight z`. + * $willNotTerminateInf + * $orderDependentFold + * + * @param z the start value + * @param op the binary operator + * @tparam B the result type of the binary operator. + * @return the result of inserting `op` between consecutive elements of this $coll, + * going right to left with the start value `z` on the right: + * {{{ + * op(x,,1,,, op(x,,2,,, ... op(x,,n,,, z)...)) + * }}} + * where `x,,1,,, ..., x,,n,,` are the elements of this $coll. + */ + def :\[B](z: B)(op: (A, B) => B): B + + /** Applies a binary operator to a start value and all elements of this $coll, + * going left to right. + * + * $willNotTerminateInf + * $orderDependentFold + * + * @param z the start value. + * @param op the binary operator. + * @tparam B the result type of the binary operator. + * @return the result of inserting `op` between consecutive elements of this $coll, + * going left to right with the start value `z` on the left: + * {{{ + * op(...op(z, x,,1,,), x,,2,,, ..., x,,n,,) + * }}} + * where `x,,1,,, ..., x,,n,,` are the elements of this $coll. + */ + def foldLeft[B](z: B)(op: (B, A) => B): B + + /** Applies a binary operator to all elements of this $coll and a start value, + * going right to left. + * + * $willNotTerminateInf + * $orderDependentFold + * @param z the start value. + * @param op the binary operator. + * @tparam B the result type of the binary operator. + * @return the result of inserting `op` between consecutive elements of this $coll, + * going right to left with the start value `z` on the right: + * {{{ + * op(x,,1,,, op(x,,2,,, ... op(x,,n,,, z)...)) + * }}} + * where `x,,1,,, ..., x,,n,,` are the elements of this $coll. + */ + def foldRight[B](z: B)(op: (A, B) => B): B + + /** Aggregates the results of applying an operator to subsequent elements. + * + * This is a more general form of `fold` and `reduce`. It has similar semantics, but does + * not require the result to be a supertype of the element type. It traverses the elements in + * different partitions sequentially, using `seqop` to update the result, and then + * applies `combop` to results from different partitions. The implementation of this + * operation may operate on an arbitrary number of collection partitions, so `combop` + * may be invoked arbitrary number of times. + * + * For example, one might want to process some elements and then produce a `Set`. In this + * case, `seqop` would process an element and append it to the list, while `combop` + * would concatenate two lists from different partitions together. The initial value + * `z` would be an empty set. + * + * {{{ + * pc.aggregate(Set[Int]())(_ += process(_), _ ++ _) + * }}} + * + * Another example is calculating geometric mean from a collection of doubles + * (one would typically require big doubles for this). + * + * @tparam S the type of accumulated results + * @param z the initial value for the accumulated result of the partition - this + * will typically be the neutral element for the `seqop` operator (e.g. + * `Nil` for list concatenation or `0` for summation) + * @param seqop an operator used to accumulate results within a partition + * @param combop an associative operator used to combine results from different partitions + */ + def aggregate[B](z: B)(seqop: (B, A) => B, combop: (B, B) => B): B + + /** Applies a binary operator to all elements of this $coll, going right to left. + * $willNotTerminateInf + * $orderDependentFold + * + * @param op the binary operator. + * @tparam B the result type of the binary operator. + * @return the result of inserting `op` between consecutive elements of this $coll, + * going right to left: + * {{{ + * op(x,,1,,, op(x,,2,,, ..., op(x,,n-1,,, x,,n,,)...)) + * }}} + * where `x,,1,,, ..., x,,n,,` are the elements of this $coll. + * @throws `UnsupportedOperationException` if this $coll is empty. + */ + def reduceRight[B >: A](op: (A, B) => B): B + + /** Optionally applies a binary operator to all elements of this $coll, going left to right. + * $willNotTerminateInf + * $orderDependentFold + * + * @param op the binary operator. + * @tparam B the result type of the binary operator. + * @return an option value containing the result of `reduceLeft(op)` is this $coll is nonempty, + * `None` otherwise. + */ + def reduceLeftOption[B >: A](op: (B, A) => B): Option[B] + + /** Optionally applies a binary operator to all elements of this $coll, going + * right to left. + * $willNotTerminateInf + * $orderDependentFold + * + * @param op the binary operator. + * @tparam B the result type of the binary operator. + * @return an option value containing the result of `reduceRight(op)` is this $coll is nonempty, + * `None` otherwise. + */ + def reduceRightOption[B >: A](op: (A, B) => B): Option[B] + + /** Counts the number of elements in the $coll which satisfy a predicate. + * + * @param p the predicate used to test elements. + * @return the number of elements satisfying the predicate `p`. + */ + def count(p: A => Boolean): Int + + /** Sums up the elements of this collection. + * + * @param num an implicit parameter defining a set of numeric operations + * which includes the `+` operator to be used in forming the sum. + * @tparam B the result type of the `+` operator. + * @return the sum of all elements of this $coll with respect to the `+` operator in `num`. + * + * @usecase def sum: A + * + * @return the sum of all elements in this $coll of numbers of type `Int`. + * Instead of `Int`, any other type `T` with an implicit `Numeric[T]` implementation + * can be used as element type of the $coll and as result type of `sum`. + * Examples of such types are: `Long`, `Float`, `Double`, `BigInt`. + * + */ + def sum[A1 >: A](implicit num: Numeric[A1]): A1 + + /** Multiplies up the elements of this collection. + * + * @param num an implicit parameter defining a set of numeric operations + * which includes the `*` operator to be used in forming the product. + * @tparam B the result type of the `*` operator. + * @return the product of all elements of this $coll with respect to the `*` operator in `num`. + * + * @usecase def product: A + * + * @return the product of all elements in this $coll of numbers of type `Int`. + * Instead of `Int`, any other type `T` with an implicit `Numeric[T]` implementation + * can be used as element type of the $coll and as result type of `product`. + * Examples of such types are: `Long`, `Float`, `Double`, `BigInt`. + */ + def product[A1 >: A](implicit num: Numeric[A1]): A1 + + /** Finds the smallest element. + * + * @param cmp An ordering to be used for comparing elements. + * @tparam B The type over which the ordering is defined. + * @return the smallest element of this $coll with respect to the ordering `cmp`. + * + * @usecase def min: A + * @return the smallest element of this $coll + */ + def min[A1 >: A](implicit ord: Ordering[A1]): A + + /** Finds the largest element. + * + * @param cmp An ordering to be used for comparing elements. + * @tparam B The type over which the ordering is defined. + * @return the largest element of this $coll with respect to the ordering `cmp`. + * + * @usecase def max: A + * @return the largest element of this $coll. + */ + def max[A1 >: A](implicit ord: Ordering[A1]): A + + def maxBy[B](f: A => B)(implicit cmp: Ordering[B]): A + + def minBy[B](f: A => B)(implicit cmp: Ordering[B]): A + + def forall(pred: A => Boolean): Boolean + + def exists(pred: A => Boolean): Boolean + + /** Finds the first element of the $coll satisfying a predicate, if any. + * + * $mayNotTerminateInf + * $orderDependent + * + * @param p the predicate used to test elements. + * @return an option value containing the first element in the $coll + * that satisfies `p`, or `None` if none exists. + */ + def find(pred: A => Boolean): Option[A] + + /** Copies values of this $coll to an array. + * Fills the given array `xs` with values of this $coll. + * Copying will stop once either the end of the current $coll is reached, + * or the end of the array is reached. + * + * $willNotTerminateInf + * + * @param xs the array to fill. + * @tparam B the type of the elements of the array. + * + * @usecase def copyToArray(xs: Array[A]): Unit + */ + def copyToArray[B >: A](xs: Array[B]): Unit + + /** Copies values of this $coll to an array. + * Fills the given array `xs` with values of this $coll, after skipping `start` values. + * Copying will stop once either the end of the current $coll is reached, + * or the end of the array is reached. + * + * $willNotTerminateInf + * + * @param xs the array to fill. + * @param start the starting index. + * @tparam B the type of the elements of the array. + * + * @usecase def copyToArray(xs: Array[A], start: Int): Unit + */ + def copyToArray[B >: A](xs: Array[B], start: Int): Unit + + def copyToArray[B >: A](xs: Array[B], start: Int, len: Int): Unit + + /** Displays all elements of this $coll in a string using start, end, and + * separator strings. + * + * @param start the starting string. + * @param sep the separator string. + * @param end the ending string. + * @return a string representation of this $coll. The resulting string + * begins with the string `start` and ends with the string + * `end`. Inside, the string representations (w.r.t. the method + * `toString`) of all elements of this $coll are separated by + * the string `sep`. + * + * @example `List(1, 2, 3).mkString("(", "; ", ")") = "(1; 2; 3)"` + */ + def mkString(start: String, sep: String, end: String): String + + /** Displays all elements of this $coll in a string using a separator string. + * + * @param sep the separator string. + * @return a string representation of this $coll. In the resulting string + * the string representations (w.r.t. the method `toString`) + * of all elements of this $coll are separated by the string `sep`. + * + * @example `List(1, 2, 3).mkString("|") = "1|2|3"` + */ + def mkString(sep: String): String + + /** Displays all elements of this $coll in a string. + * + * @return a string representation of this $coll. In the resulting string + * the string representations (w.r.t. the method `toString`) + * of all elements of this $coll follow each other without any + * separator string. + */ + def mkString: String + + /** Converts this $coll to an array. + * $willNotTerminateInf + * + * @tparam B the type of the elements of the array. A `ClassManifest` for + * this type must be available. + * @return an array containing all elements of this $coll. + * + * @usecase def toArray: Array[A] + * @return an array containing all elements of this $coll. + * A `ClassManifest` must be available for the element type of this $coll. + */ + def toArray[A1 >: A: ClassManifest]: Array[A1] + + /** Converts this $coll to a list. + * $willNotTerminateInf + * @return a list containing all elements of this $coll. + */ + def toList: List[A] + + /** Converts this $coll to an indexed sequence. + * $willNotTerminateInf + * @return an indexed sequence containing all elements of this $coll. + */ + def toIndexedSeq[A1 >: A]: immutable.IndexedSeq[A1] + + /** Converts this $coll to a stream. + * $willNotTerminateInf + * @return a stream containing all elements of this $coll. + */ + def toStream: Stream[A] + + /** Returns an Iterator over the elements in this $coll. Will return + * the same Iterator if this instance is already an Iterator. + * $willNotTerminateInf + * @return an Iterator containing all elements of this $coll. + */ + def toIterator: Iterator[A] + + /** Converts this $coll to a mutable buffer. + * $willNotTerminateInf + * @return a buffer containing all elements of this $coll. + */ + def toBuffer[A1 >: A]: collection.mutable.Buffer[A1] + + /** Converts this $coll to an unspecified Traversable. Will return + * the same collection if this instance is already Traversable. + * $willNotTerminateInf + * @return a Traversable containing all elements of this $coll. + */ + def toTraversable: GenTraversable[A] + + /** Converts this $coll to an iterable collection. Note that + * the choice of target `Iterable` is lazy in this default implementation + * as this `TraversableOnce` may be lazy and unevaluated (i.e. it may + * be an iterator which is only traversable once). + * + * $willNotTerminateInf + * @return an `Iterable` containing all elements of this $coll. + */ + def toIterable: GenIterable[A] + + /** Converts this $coll to a sequence. As with `toIterable`, it's lazy + * in this default implementation, as this `TraversableOnce` may be + * lazy and unevaluated. + * + * $willNotTerminateInf + * @return a sequence containing all elements of this $coll. + */ + def toSeq: GenSeq[A] + + /** Converts this $coll to a set. + * $willNotTerminateInf + * @return a set containing all elements of this $coll. + */ + def toSet[A1 >: A]: GenSet[A1] + + /** Converts this $coll to a map. This method is unavailable unless + * the elements are members of Tuple2, each ((T, U)) becoming a key-value + * pair in the map. Duplicate keys will be overwritten by later keys: + * if this is an unordered collection, which key is in the resulting map + * is undefined. + * $willNotTerminateInf + * @return a map containing all elements of this $coll. + * @usecase def toMap[T, U]: Map[T, U] + * @return a map of type `immutable.Map[T, U]` + * containing all key/value pairs of type `(T, U)` of this $coll. + */ + def toMap[K, V](implicit ev: A <:< (K, V)): GenMap[K, V] } diff --git a/src/library/scala/collection/GenTraversableOnceLike.scala b/src/library/scala/collection/GenTraversableOnceLike.scala deleted file mode 100644 index 6431b334cf..0000000000 --- a/src/library/scala/collection/GenTraversableOnceLike.scala +++ /dev/null @@ -1,510 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -package scala.collection - -/** A template trait for all traversable-once objects which may be - * traversed in parallel. - * - * Methods in this trait are either abstract or can be implemented in terms - * of other methods. - * - * @define Coll GenTraversableOnce - * @define coll collection or iterator - * @define possiblyparinfo - * This trait may possibly have operations implemented in parallel. - * @define undefinedorder - * The order in which operations are performed on elements is unspecified and may be nondeterministic. - * @define orderDependent - * - * Note: might return different results for different runs, unless the underlying collection type is ordered. - * @define orderDependentFold - * - * Note: might return different results for different runs, unless the - * underlying collection type is ordered or the operator is associative - * and commutative. - * @define mayNotTerminateInf - * - * Note: may not terminate for infinite-sized collections. - * @define willNotTerminateInf - * - * Note: will not terminate for infinite-sized collections. - * - * @author Martin Odersky - * @author Aleksandar Prokopec - * @since 2.9 - */ -private[collection] trait GenTraversableOnceLike[+A] { - - def foreach[U](f: A => U): Unit - - def hasDefiniteSize: Boolean - - def seq: TraversableOnce[A] - - /** The size of this $coll. - * - * $willNotTerminateInf - * - * @return the number of elements in this $coll. - */ - def size: Int - - /** Tests whether the $coll is empty. - * - * @return `true` if the $coll contains no elements, `false` otherwise. - */ - def isEmpty: Boolean - - /** Tests whether the $coll is not empty. - * - * @return `true` if the $coll contains at least one element, `false` otherwise. - */ - def nonEmpty: Boolean - - /** Tests whether this $coll can be repeatedly traversed. Always - * true for Traversables and false for Iterators unless overridden. - * - * @return `true` if it is repeatedly traversable, `false` otherwise. - */ - def isTraversableAgain: Boolean - - /** Reduces the elements of this sequence using the specified associative binary operator. - * - * $undefinedorder - * - * Note this method has a different signature than the `reduceLeft` - * and `reduceRight` methods of the trait `Traversable`. - * The result of reducing may only be a supertype of this parallel collection's - * type parameter `T`. - * - * @tparam U A type parameter for the binary operator, a supertype of `T`. - * @param op A binary operator that must be associative. - * @return The result of applying reduce operator `op` between all the elements if the collection is nonempty. - * @throws UnsupportedOperationException - * if this $coll is empty. - */ - def reduce[A1 >: A](op: (A1, A1) => A1): A1 - - /** Optionally reduces the elements of this sequence using the specified associative binary operator. - * - * $undefinedorder - * - * Note this method has a different signature than the `reduceLeftOption` - * and `reduceRightOption` methods of the trait `Traversable`. - * The result of reducing may only be a supertype of this parallel collection's - * type parameter `T`. - * - * @tparam U A type parameter for the binary operator, a supertype of `T`. - * @param op A binary operator that must be associative. - * @return An option value containing result of applying reduce operator `op` between all - * the elements if the collection is nonempty, and `None` otherwise. - */ - def reduceOption[A1 >: A](op: (A1, A1) => A1): Option[A1] - - /** Folds the elements of this sequence using the specified associative binary operator. - * The order in which the elements are reduced is unspecified and may be nondeterministic. - * - * Note this method has a different signature than the `foldLeft` - * and `foldRight` methods of the trait `Traversable`. - * The result of folding may only be a supertype of this parallel collection's - * type parameter `T`. - * - * @tparam U a type parameter for the binary operator, a supertype of `T`. - * @param z a neutral element for the fold operation, it may be added to the result - * an arbitrary number of times, not changing the result (e.g. `Nil` for list concatenation, - * 0 for addition, or 1 for multiplication) - * @param op a binary operator that must be associative - * @return the result of applying fold operator `op` between all the elements and `z` - */ - def fold[A1 >: A](z: A1)(op: (A1, A1) => A1): A1 - - /** A syntactic sugar for out of order folding. See `fold`. */ - def /:\[A1 >: A](z: A1)(op: (A1, A1) => A1): A1 = fold(z)(op) - - /** Applies a binary operator to a start value and all elements of this $coll, - * going left to right. - * - * Note: `/:` is alternate syntax for `foldLeft`; `z /: xs` is the same as - * `xs foldLeft z`. - * $willNotTerminateInf - * $orderDependentFold - * - * @param z the start value. - * @param op the binary operator. - * @tparam B the result type of the binary operator. - * @return the result of inserting `op` between consecutive elements of this $coll, - * going left to right with the start value `z` on the left: - * {{{ - * op(...op(op(z, x,,1,,), x,,2,,), ..., x,,n,,) - * }}} - * where `x,,1,,, ..., x,,n,,` are the elements of this $coll. - */ - def /:[B](z: B)(op: (B, A) => B): B - - /** Applies a binary operator to all elements of this $coll and a start value, - * going right to left. - * - * Note: `:\` is alternate syntax for `foldRight`; `xs :\ z` is the same as - * `xs foldRight z`. - * $willNotTerminateInf - * $orderDependentFold - * - * @param z the start value - * @param op the binary operator - * @tparam B the result type of the binary operator. - * @return the result of inserting `op` between consecutive elements of this $coll, - * going right to left with the start value `z` on the right: - * {{{ - * op(x,,1,,, op(x,,2,,, ... op(x,,n,,, z)...)) - * }}} - * where `x,,1,,, ..., x,,n,,` are the elements of this $coll. - */ - def :\[B](z: B)(op: (A, B) => B): B - - /** Applies a binary operator to a start value and all elements of this $coll, - * going left to right. - * - * $willNotTerminateInf - * $orderDependentFold - * - * @param z the start value. - * @param op the binary operator. - * @tparam B the result type of the binary operator. - * @return the result of inserting `op` between consecutive elements of this $coll, - * going left to right with the start value `z` on the left: - * {{{ - * op(...op(z, x,,1,,), x,,2,,, ..., x,,n,,) - * }}} - * where `x,,1,,, ..., x,,n,,` are the elements of this $coll. - */ - def foldLeft[B](z: B)(op: (B, A) => B): B - - /** Applies a binary operator to all elements of this $coll and a start value, - * going right to left. - * - * $willNotTerminateInf - * $orderDependentFold - * @param z the start value. - * @param op the binary operator. - * @tparam B the result type of the binary operator. - * @return the result of inserting `op` between consecutive elements of this $coll, - * going right to left with the start value `z` on the right: - * {{{ - * op(x,,1,,, op(x,,2,,, ... op(x,,n,,, z)...)) - * }}} - * where `x,,1,,, ..., x,,n,,` are the elements of this $coll. - */ - def foldRight[B](z: B)(op: (A, B) => B): B - - /** Aggregates the results of applying an operator to subsequent elements. - * - * This is a more general form of `fold` and `reduce`. It has similar semantics, but does - * not require the result to be a supertype of the element type. It traverses the elements in - * different partitions sequentially, using `seqop` to update the result, and then - * applies `combop` to results from different partitions. The implementation of this - * operation may operate on an arbitrary number of collection partitions, so `combop` - * may be invoked arbitrary number of times. - * - * For example, one might want to process some elements and then produce a `Set`. In this - * case, `seqop` would process an element and append it to the list, while `combop` - * would concatenate two lists from different partitions together. The initial value - * `z` would be an empty set. - * - * {{{ - * pc.aggregate(Set[Int]())(_ += process(_), _ ++ _) - * }}} - * - * Another example is calculating geometric mean from a collection of doubles - * (one would typically require big doubles for this). - * - * @tparam S the type of accumulated results - * @param z the initial value for the accumulated result of the partition - this - * will typically be the neutral element for the `seqop` operator (e.g. - * `Nil` for list concatenation or `0` for summation) - * @param seqop an operator used to accumulate results within a partition - * @param combop an associative operator used to combine results from different partitions - */ - def aggregate[B](z: B)(seqop: (B, A) => B, combop: (B, B) => B): B - - /** Applies a binary operator to all elements of this $coll, going right to left. - * $willNotTerminateInf - * $orderDependentFold - * - * @param op the binary operator. - * @tparam B the result type of the binary operator. - * @return the result of inserting `op` between consecutive elements of this $coll, - * going right to left: - * {{{ - * op(x,,1,,, op(x,,2,,, ..., op(x,,n-1,,, x,,n,,)...)) - * }}} - * where `x,,1,,, ..., x,,n,,` are the elements of this $coll. - * @throws `UnsupportedOperationException` if this $coll is empty. - */ - def reduceRight[B >: A](op: (A, B) => B): B - - /** Optionally applies a binary operator to all elements of this $coll, going left to right. - * $willNotTerminateInf - * $orderDependentFold - * - * @param op the binary operator. - * @tparam B the result type of the binary operator. - * @return an option value containing the result of `reduceLeft(op)` is this $coll is nonempty, - * `None` otherwise. - */ - def reduceLeftOption[B >: A](op: (B, A) => B): Option[B] - - /** Optionally applies a binary operator to all elements of this $coll, going - * right to left. - * $willNotTerminateInf - * $orderDependentFold - * - * @param op the binary operator. - * @tparam B the result type of the binary operator. - * @return an option value containing the result of `reduceRight(op)` is this $coll is nonempty, - * `None` otherwise. - */ - def reduceRightOption[B >: A](op: (A, B) => B): Option[B] - - /** Counts the number of elements in the $coll which satisfy a predicate. - * - * @param p the predicate used to test elements. - * @return the number of elements satisfying the predicate `p`. - */ - def count(p: A => Boolean): Int - - /** Sums up the elements of this collection. - * - * @param num an implicit parameter defining a set of numeric operations - * which includes the `+` operator to be used in forming the sum. - * @tparam B the result type of the `+` operator. - * @return the sum of all elements of this $coll with respect to the `+` operator in `num`. - * - * @usecase def sum: A - * - * @return the sum of all elements in this $coll of numbers of type `Int`. - * Instead of `Int`, any other type `T` with an implicit `Numeric[T]` implementation - * can be used as element type of the $coll and as result type of `sum`. - * Examples of such types are: `Long`, `Float`, `Double`, `BigInt`. - * - */ - def sum[A1 >: A](implicit num: Numeric[A1]): A1 - - /** Multiplies up the elements of this collection. - * - * @param num an implicit parameter defining a set of numeric operations - * which includes the `*` operator to be used in forming the product. - * @tparam B the result type of the `*` operator. - * @return the product of all elements of this $coll with respect to the `*` operator in `num`. - * - * @usecase def product: A - * - * @return the product of all elements in this $coll of numbers of type `Int`. - * Instead of `Int`, any other type `T` with an implicit `Numeric[T]` implementation - * can be used as element type of the $coll and as result type of `product`. - * Examples of such types are: `Long`, `Float`, `Double`, `BigInt`. - */ - def product[A1 >: A](implicit num: Numeric[A1]): A1 - - /** Finds the smallest element. - * - * @param cmp An ordering to be used for comparing elements. - * @tparam B The type over which the ordering is defined. - * @return the smallest element of this $coll with respect to the ordering `cmp`. - * - * @usecase def min: A - * @return the smallest element of this $coll - */ - def min[A1 >: A](implicit ord: Ordering[A1]): A - - /** Finds the largest element. - * - * @param cmp An ordering to be used for comparing elements. - * @tparam B The type over which the ordering is defined. - * @return the largest element of this $coll with respect to the ordering `cmp`. - * - * @usecase def max: A - * @return the largest element of this $coll. - */ - def max[A1 >: A](implicit ord: Ordering[A1]): A - - def maxBy[B](f: A => B)(implicit cmp: Ordering[B]): A - - def minBy[B](f: A => B)(implicit cmp: Ordering[B]): A - - def forall(pred: A => Boolean): Boolean - - def exists(pred: A => Boolean): Boolean - - /** Finds the first element of the $coll satisfying a predicate, if any. - * - * $mayNotTerminateInf - * $orderDependent - * - * @param p the predicate used to test elements. - * @return an option value containing the first element in the $coll - * that satisfies `p`, or `None` if none exists. - */ - def find(pred: A => Boolean): Option[A] - - /** Copies values of this $coll to an array. - * Fills the given array `xs` with values of this $coll. - * Copying will stop once either the end of the current $coll is reached, - * or the end of the array is reached. - * - * $willNotTerminateInf - * - * @param xs the array to fill. - * @tparam B the type of the elements of the array. - * - * @usecase def copyToArray(xs: Array[A]): Unit - */ - def copyToArray[B >: A](xs: Array[B]): Unit - - /** Copies values of this $coll to an array. - * Fills the given array `xs` with values of this $coll, after skipping `start` values. - * Copying will stop once either the end of the current $coll is reached, - * or the end of the array is reached. - * - * $willNotTerminateInf - * - * @param xs the array to fill. - * @param start the starting index. - * @tparam B the type of the elements of the array. - * - * @usecase def copyToArray(xs: Array[A], start: Int): Unit - */ - def copyToArray[B >: A](xs: Array[B], start: Int): Unit - - def copyToArray[B >: A](xs: Array[B], start: Int, len: Int): Unit - - /** Displays all elements of this $coll in a string using start, end, and - * separator strings. - * - * @param start the starting string. - * @param sep the separator string. - * @param end the ending string. - * @return a string representation of this $coll. The resulting string - * begins with the string `start` and ends with the string - * `end`. Inside, the string representations (w.r.t. the method - * `toString`) of all elements of this $coll are separated by - * the string `sep`. - * - * @example `List(1, 2, 3).mkString("(", "; ", ")") = "(1; 2; 3)"` - */ - def mkString(start: String, sep: String, end: String): String - - /** Displays all elements of this $coll in a string using a separator string. - * - * @param sep the separator string. - * @return a string representation of this $coll. In the resulting string - * the string representations (w.r.t. the method `toString`) - * of all elements of this $coll are separated by the string `sep`. - * - * @example `List(1, 2, 3).mkString("|") = "1|2|3"` - */ - def mkString(sep: String): String - - /** Displays all elements of this $coll in a string. - * - * @return a string representation of this $coll. In the resulting string - * the string representations (w.r.t. the method `toString`) - * of all elements of this $coll follow each other without any - * separator string. - */ - def mkString: String - - /** Converts this $coll to an array. - * $willNotTerminateInf - * - * @tparam B the type of the elements of the array. A `ClassManifest` for - * this type must be available. - * @return an array containing all elements of this $coll. - * - * @usecase def toArray: Array[A] - * @return an array containing all elements of this $coll. - * A `ClassManifest` must be available for the element type of this $coll. - */ - def toArray[A1 >: A: ClassManifest]: Array[A1] - - /** Converts this $coll to a list. - * $willNotTerminateInf - * @return a list containing all elements of this $coll. - */ - def toList: List[A] - - /** Converts this $coll to an indexed sequence. - * $willNotTerminateInf - * @return an indexed sequence containing all elements of this $coll. - */ - def toIndexedSeq[A1 >: A]: immutable.IndexedSeq[A1] - - /** Converts this $coll to a stream. - * $willNotTerminateInf - * @return a stream containing all elements of this $coll. - */ - def toStream: Stream[A] - - /** Returns an Iterator over the elements in this $coll. Will return - * the same Iterator if this instance is already an Iterator. - * $willNotTerminateInf - * @return an Iterator containing all elements of this $coll. - */ - def toIterator: Iterator[A] - - /** Converts this $coll to a mutable buffer. - * $willNotTerminateInf - * @return a buffer containing all elements of this $coll. - */ - def toBuffer[A1 >: A]: collection.mutable.Buffer[A1] - - /** Converts this $coll to an unspecified Traversable. Will return - * the same collection if this instance is already Traversable. - * $willNotTerminateInf - * @return a Traversable containing all elements of this $coll. - */ - def toTraversable: GenTraversable[A] - - /** Converts this $coll to an iterable collection. Note that - * the choice of target `Iterable` is lazy in this default implementation - * as this `TraversableOnce` may be lazy and unevaluated (i.e. it may - * be an iterator which is only traversable once). - * - * $willNotTerminateInf - * @return an `Iterable` containing all elements of this $coll. - */ - def toIterable: GenIterable[A] - - /** Converts this $coll to a sequence. As with `toIterable`, it's lazy - * in this default implementation, as this `TraversableOnce` may be - * lazy and unevaluated. - * - * $willNotTerminateInf - * @return a sequence containing all elements of this $coll. - */ - def toSeq: GenSeq[A] - - /** Converts this $coll to a set. - * $willNotTerminateInf - * @return a set containing all elements of this $coll. - */ - def toSet[A1 >: A]: GenSet[A1] - - /** Converts this $coll to a map. This method is unavailable unless - * the elements are members of Tuple2, each ((T, U)) becoming a key-value - * pair in the map. Duplicate keys will be overwritten by later keys: - * if this is an unordered collection, which key is in the resulting map - * is undefined. - * $willNotTerminateInf - * @return a map containing all elements of this $coll. - * @usecase def toMap[T, U]: Map[T, U] - * @return a map of type `immutable.Map[T, U]` - * containing all key/value pairs of type `(T, U)` of this $coll. - */ - def toMap[K, V](implicit ev: A <:< (K, V)): GenMap[K, V] -} diff --git a/src/library/scala/collection/Iterator.scala b/src/library/scala/collection/Iterator.scala index 082ffb464e..7bd33cbb23 100644 --- a/src/library/scala/collection/Iterator.scala +++ b/src/library/scala/collection/Iterator.scala @@ -253,6 +253,8 @@ import Iterator.empty trait Iterator[+A] extends TraversableOnce[A] { self => + def seq: Iterator[A] = this + /** Tests whether this iterator can provide another element. * @return `true` if a subsequent call to `next` will yield an element, * `false` otherwise. diff --git a/src/library/scala/collection/TraversableLike.scala b/src/library/scala/collection/TraversableLike.scala index bffd46a72c..2d3a4c229c 100644 --- a/src/library/scala/collection/TraversableLike.scala +++ b/src/library/scala/collection/TraversableLike.scala @@ -68,7 +68,7 @@ import parallel.ParIterable */ trait TraversableLike[+A, +Repr] extends HasNewBuilder[A, Repr] with FilterMonadic[A, Repr] - with TraversableOnceLike[A] + with TraversableOnce[A] with GenTraversableLike[A, Repr] with Parallelizable[A, ParIterable[A]] { diff --git a/src/library/scala/collection/TraversableOnce.scala b/src/library/scala/collection/TraversableOnce.scala index 23e3f2a866..90f1583c58 100644 --- a/src/library/scala/collection/TraversableOnce.scala +++ b/src/library/scala/collection/TraversableOnce.scala @@ -13,10 +13,6 @@ import annotation.unchecked.{ uncheckedVariance => uV } /** A template trait for collections which can be traversed either once only * or one or more times. - * - * All of the methods in this trait are guaranteed to be implemented - * in a single-threaded manner. - * * $traversableonceinfo * * @tparam A the element type of the collection @@ -27,6 +23,24 @@ import annotation.unchecked.{ uncheckedVariance => uV } * @since 2.8 * * @define coll traversable or iterator + * + * @tparam A the element type of the collection + * + * @define traversableonceinfo + * This trait exists primarily to eliminate code duplication between + * `Iterator` and `Traversable`, and thus implements some of the common + * methods that can be implemented solely in terms of foreach without + * access to a `Builder`. It also includes a number of abstract methods + * whose implementations are provided by `Iterator`, `Traversable`, etc. + * It contains implementations common to `Iterators` and + * `Traversables`, such as folds, conversions, and other operations which + * traverse some or all of the elements and return a derived value. + * Directly subclassing `TraversableOnce` is not recommended - instead, + * consider declaring an `Iterator` with a `next` and `hasNext` method, + * creating an `Iterator` with one of the methods on the `Iterator` object, + * or declaring a subclass of `Traversable`. + * + * @define coll traversable or iterator * @define orderDependent * * Note: might return different results for different runs, unless the underlying collection type is ordered. @@ -42,14 +56,270 @@ import annotation.unchecked.{ uncheckedVariance => uV } * * Note: will not terminate for infinite-sized collections. */ -trait TraversableOnce[+A] extends GenTraversableOnce[A] with TraversableOnceLike[A] { +trait TraversableOnce[+A] extends GenTraversableOnce[A] { self => - override def seq: TraversableOnce[A] = this + /** Self-documenting abstract methods. */ + def foreach[U](f: A => U): Unit + def isEmpty: Boolean + def hasDefiniteSize: Boolean + + // Note: We could redefine this in TraversableLike to always return `repr` + // of type `Repr`, only if `Repr` had type bounds, which it doesn't, because + // not all `Repr` are a subtype `TraversableOnce[A]`. + // The alternative is redefining it for maps, sets and seqs. For concrete implementations + // we don't have to do this anyway, since they are leaves in the inheritance hierarchy. + // Note 2: This is implemented in all collections _not_ inheriting `Traversable[A]` + // at least indirectly. Currently, these are `ArrayOps` and `StringOps`. + // It is also implemented in `TraversableOnce[A]`. + /** A version of this collection with all + * of the operations implemented sequentially (i.e. in a single-threaded manner). + * + * This method returns a reference to this collection. In parallel collections, + * it is redefined to return a sequential implementation of this collection. In + * both cases, it has O(1) complexity. + * + * @return a sequential view of the collection. + */ + def seq: TraversableOnce[A] + + /** Presently these are abstract because the Traversable versions use + * breakable/break, and I wasn't sure enough of how that's supposed to + * function to consolidate them with the Iterator versions. + */ + def forall(p: A => Boolean): Boolean + def exists(p: A => Boolean): Boolean + def find(p: A => Boolean): Option[A] + def copyToArray[B >: A](xs: Array[B], start: Int, len: Int): Unit + + // for internal use + protected[this] def reversed = { + var elems: List[A] = Nil + self.seq foreach (elems ::= _) + elems + } + + def size: Int = { + var result = 0 + for (x <- self) result += 1 + result + } + + def nonEmpty: Boolean = !isEmpty + + def count(p: A => Boolean): Int = { + var cnt = 0 + for (x <- this) + if (p(x)) cnt += 1 + + cnt + } + + /** Finds the first element of the $coll for which the given partial + * function is defined, and applies the partial function to it. + * + * $mayNotTerminateInf + * $orderDependent + * + * @param pf the partial function + * @return an option value containing pf applied to the first + * value for which it is defined, or `None` if none exists. + * @example `Seq("a", 1, 5L).collectFirst({ case x: Int => x*10 }) = Some(10)` + */ + def collectFirst[B](pf: PartialFunction[A, B]): Option[B] = { + for (x <- self.toIterator) { // make sure to use an iterator or `seq` + if (pf isDefinedAt x) + return Some(pf(x)) + } + None + } + + def /:[B](z: B)(op: (B, A) => B): B = foldLeft(z)(op) + + def :\[B](z: B)(op: (A, B) => B): B = foldRight(z)(op) + + def foldLeft[B](z: B)(op: (B, A) => B): B = { + var result = z + this.seq foreach (x => result = op(result, x)) + result + } + + def foldRight[B](z: B)(op: (A, B) => B): B = + reversed.foldLeft(z)((x, y) => op(y, x)) + + def reduceLeft[B >: A](op: (B, A) => B): B = { + if (isEmpty) + throw new UnsupportedOperationException("empty.reduceLeft") + + var first = true + var acc: B = 0.asInstanceOf[B] + + for (x <- self) { + if (first) { + acc = x + first = false + } + else acc = op(acc, x) + } + acc + } + + def reduceRight[B >: A](op: (A, B) => B): B = { + if (isEmpty) + throw new UnsupportedOperationException("empty.reduceRight") + + reversed.reduceLeft[B]((x, y) => op(y, x)) + } + + def reduceLeftOption[B >: A](op: (B, A) => B): Option[B] = + if (isEmpty) None else Some(reduceLeft(op)) + + def reduceRightOption[B >: A](op: (A, B) => B): Option[B] = + if (isEmpty) None else Some(reduceRight(op)) + + def reduce[A1 >: A](op: (A1, A1) => A1): A1 = reduceLeft(op) + + def reduceOption[A1 >: A](op: (A1, A1) => A1): Option[A1] = reduceLeftOption(op) + + def fold[A1 >: A](z: A1)(op: (A1, A1) => A1): A1 = foldLeft(z)(op) + + def aggregate[B](z: B)(seqop: (B, A) => B, combop: (B, B) => B): B = foldLeft(z)(seqop) + + def sum[B >: A](implicit num: Numeric[B]): B = foldLeft(num.zero)(num.plus) + def product[B >: A](implicit num: Numeric[B]): B = foldLeft(num.one)(num.times) + + def min[B >: A](implicit cmp: Ordering[B]): A = { + if (isEmpty) + throw new UnsupportedOperationException("empty.min") + + reduceLeft((x, y) => if (cmp.lteq(x, y)) x else y) + } + + def max[B >: A](implicit cmp: Ordering[B]): A = { + if (isEmpty) + throw new UnsupportedOperationException("empty.max") + + reduceLeft((x, y) => if (cmp.gteq(x, y)) x else y) + } + + def maxBy[B](f: A => B)(implicit cmp: Ordering[B]): A = { + if (isEmpty) + throw new UnsupportedOperationException("empty.maxBy") + + reduceLeft((x, y) => if (cmp.gteq(f(x), f(y))) x else y) + } + def minBy[B](f: A => B)(implicit cmp: Ordering[B]): A = { + if (isEmpty) + throw new UnsupportedOperationException("empty.minBy") + + reduceLeft((x, y) => if (cmp.lteq(f(x), f(y))) x else y) + } + + /** Copies all elements of this $coll to a buffer. + * $willNotTerminateInf + * @param dest The buffer to which elements are copied. + */ + def copyToBuffer[B >: A](dest: Buffer[B]): Unit = dest ++= seq + + def copyToArray[B >: A](xs: Array[B], start: Int): Unit = + copyToArray(xs, start, xs.length - start) + + def copyToArray[B >: A](xs: Array[B]): Unit = + copyToArray(xs, 0, xs.length) + + def toArray[B >: A : ClassManifest]: Array[B] = { + if (isTraversableAgain) { + val result = new Array[B](size) + copyToArray(result, 0) + result + } + else toBuffer.toArray + } + + def toTraversable: Traversable[A] + + def toList: List[A] = new ListBuffer[A] ++= seq toList + + def toIterable: Iterable[A] = toStream + + def toSeq: Seq[A] = toStream + + def toIndexedSeq[B >: A]: immutable.IndexedSeq[B] = immutable.IndexedSeq() ++ seq + + def toBuffer[B >: A]: mutable.Buffer[B] = new ArrayBuffer[B] ++= seq + + def toSet[B >: A]: immutable.Set[B] = immutable.Set() ++ seq + + def toMap[T, U](implicit ev: A <:< (T, U)): immutable.Map[T, U] = { + val b = immutable.Map.newBuilder[T, U] + for (x <- self) + b += x + + b.result + } + + def mkString(start: String, sep: String, end: String): String = + addString(new StringBuilder(), start, sep, end).toString + + def mkString(sep: String): String = mkString("", sep, "") + + def mkString: String = mkString("") + + /** Appends all elements of this $coll to a string builder using start, end, + * and separator strings. + * The written text begins with the string `start` and ends with the string + * `end`. Inside, the string representations (w.r.t. the method `toString`) + * of all elements of this $coll are separated by the string `sep`. + * + * @param b the string builder to which elements are appended. + * @param start the starting string. + * @param sep the separator string. + * @param end the ending string. + * @return the string builder `b` to which elements were appended. + */ + def addString(b: StringBuilder, start: String, sep: String, end: String): StringBuilder = { + var first = true + + b append start + for (x <- self) { + if (first) { + b append x + first = false + } + else { + b append sep + b append x + } + } + b append end + + b + } + + /** Appends all elements of this $coll to a string builder using a separator + * string. The written text consists of the string representations (w.r.t. + * the method `toString`) of all elements of this $coll, separated by the + * string `sep`. + * + * @param b the string builder to which elements are appended. + * @param sep the separator string. + * @return the string builder `b` to which elements were appended. + */ + def addString(b: StringBuilder, sep: String): StringBuilder = addString(b, "", sep, "") + + /** Appends all elements of this $coll to a string builder. + * The written text consists of the string representations (w.r.t. the method + * `toString`) of all elements of this $coll without any separator string. + * + * @param b the string builder to which elements are appended. + * @return the string builder `b` to which elements were appended. + */ + def addString(b: StringBuilder): StringBuilder = addString(b, "") } + object TraversableOnce { implicit def traversableOnceCanBuildFrom[T] = new OnceCanBuildFrom[T] implicit def wrapTraversableOnce[A](trav: TraversableOnce[A]) = new MonadOps(trav) diff --git a/src/library/scala/collection/TraversableOnceLike.scala b/src/library/scala/collection/TraversableOnceLike.scala deleted file mode 100644 index 462265f14a..0000000000 --- a/src/library/scala/collection/TraversableOnceLike.scala +++ /dev/null @@ -1,304 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -package scala.collection - -import mutable.{ Buffer, ListBuffer, ArrayBuffer } -import annotation.unchecked.{ uncheckedVariance => uV } - -/** A template trait for collections which can be traversed either once only - * or one or more times. - * $traversableonceinfo - * - * @tparam A the element type of the collection - * - * @define traversableonceinfo - * This trait exists primarily to eliminate code duplication between - * `Iterator` and `Traversable`, and thus implements some of the common - * methods that can be implemented solely in terms of foreach without - * access to a `Builder`. It also includes a number of abstract methods - * whose implementations are provided by `Iterator`, `Traversable`, etc. - * It contains implementations common to `Iterators` and - * `Traversables`, such as folds, conversions, and other operations which - * traverse some or all of the elements and return a derived value. - * Directly subclassing `TraversableOnce` is not recommended - instead, - * consider declaring an `Iterator` with a `next` and `hasNext` method, - * creating an `Iterator` with one of the methods on the `Iterator` object, - * or declaring a subclass of `Traversable`. - * - * @author Martin Odersky - * @author Paul Phillips - * @version 2.9 - * @since 2.9 - * - * @define coll traversable or iterator - */ -trait TraversableOnceLike[+A] extends GenTraversableOnceLike[A] { - self => - - /** Self-documenting abstract methods. */ - def foreach[U](f: A => U): Unit - def isEmpty: Boolean - def hasDefiniteSize: Boolean - - // Note: We could redefine this in TraversableLike to always return `repr` - // of type `Repr`, only if `Repr` had type bounds, which it doesn't, because - // not all `Repr` are a subtype `TraversableOnce[A]`. - // The alternative is redefining it for maps, sets and seqs. For concrete implementations - // we don't have to do this anyway, since they are leaves in the inheritance hierarchy. - // Note 2: This is implemented in all collections _not_ inheriting `Traversable[A]` - // at least indirectly. Currently, these are `ArrayOps` and `StringOps`. - // It is also implemented in `TraversableOnce[A]`. - /** A version of this collection with all - * of the operations implemented sequentially (i.e. in a single-threaded manner). - * - * This method returns a reference to this collection. In parallel collections, - * it is redefined to return a sequential implementation of this collection. In - * both cases, it has O(1) complexity. - * - * @return a sequential view of the collection. - */ - def seq: TraversableOnce[A] - - /** Presently these are abstract because the Traversable versions use - * breakable/break, and I wasn't sure enough of how that's supposed to - * function to consolidate them with the Iterator versions. - */ - def forall(p: A => Boolean): Boolean - def exists(p: A => Boolean): Boolean - def find(p: A => Boolean): Option[A] - def copyToArray[B >: A](xs: Array[B], start: Int, len: Int): Unit - - // for internal use - protected[this] def reversed = { - var elems: List[A] = Nil - self.seq foreach (elems ::= _) - elems - } - - def size: Int = { - var result = 0 - for (x <- self) result += 1 - result - } - - def nonEmpty: Boolean = !isEmpty - - def count(p: A => Boolean): Int = { - var cnt = 0 - for (x <- this) - if (p(x)) cnt += 1 - - cnt - } - - /** Finds the first element of the $coll for which the given partial - * function is defined, and applies the partial function to it. - * - * $mayNotTerminateInf - * $orderDependent - * - * @param pf the partial function - * @return an option value containing pf applied to the first - * value for which it is defined, or `None` if none exists. - * @example `Seq("a", 1, 5L).collectFirst({ case x: Int => x*10 }) = Some(10)` - */ - def collectFirst[B](pf: PartialFunction[A, B]): Option[B] = { - for (x <- self.toIterator) { // make sure to use an iterator or `seq` - if (pf isDefinedAt x) - return Some(pf(x)) - } - None - } - - def /:[B](z: B)(op: (B, A) => B): B = foldLeft(z)(op) - - def :\[B](z: B)(op: (A, B) => B): B = foldRight(z)(op) - - def foldLeft[B](z: B)(op: (B, A) => B): B = { - var result = z - this.seq foreach (x => result = op(result, x)) - result - } - - def foldRight[B](z: B)(op: (A, B) => B): B = - reversed.foldLeft(z)((x, y) => op(y, x)) - - def reduceLeft[B >: A](op: (B, A) => B): B = { - if (isEmpty) - throw new UnsupportedOperationException("empty.reduceLeft") - - var first = true - var acc: B = 0.asInstanceOf[B] - - for (x <- self) { - if (first) { - acc = x - first = false - } - else acc = op(acc, x) - } - acc - } - - def reduceRight[B >: A](op: (A, B) => B): B = { - if (isEmpty) - throw new UnsupportedOperationException("empty.reduceRight") - - reversed.reduceLeft[B]((x, y) => op(y, x)) - } - - def reduceLeftOption[B >: A](op: (B, A) => B): Option[B] = - if (isEmpty) None else Some(reduceLeft(op)) - - def reduceRightOption[B >: A](op: (A, B) => B): Option[B] = - if (isEmpty) None else Some(reduceRight(op)) - - def reduce[A1 >: A](op: (A1, A1) => A1): A1 = reduceLeft(op) - - def reduceOption[A1 >: A](op: (A1, A1) => A1): Option[A1] = reduceLeftOption(op) - - def fold[A1 >: A](z: A1)(op: (A1, A1) => A1): A1 = foldLeft(z)(op) - - def aggregate[B](z: B)(seqop: (B, A) => B, combop: (B, B) => B): B = foldLeft(z)(seqop) - - def sum[B >: A](implicit num: Numeric[B]): B = foldLeft(num.zero)(num.plus) - - def product[B >: A](implicit num: Numeric[B]): B = foldLeft(num.one)(num.times) - - def min[B >: A](implicit cmp: Ordering[B]): A = { - if (isEmpty) - throw new UnsupportedOperationException("empty.min") - - reduceLeft((x, y) => if (cmp.lteq(x, y)) x else y) - } - - def max[B >: A](implicit cmp: Ordering[B]): A = { - if (isEmpty) - throw new UnsupportedOperationException("empty.max") - - reduceLeft((x, y) => if (cmp.gteq(x, y)) x else y) - } - - def maxBy[B](f: A => B)(implicit cmp: Ordering[B]): A = { - if (isEmpty) - throw new UnsupportedOperationException("empty.maxBy") - - reduceLeft((x, y) => if (cmp.gteq(f(x), f(y))) x else y) - } - def minBy[B](f: A => B)(implicit cmp: Ordering[B]): A = { - if (isEmpty) - throw new UnsupportedOperationException("empty.minBy") - - reduceLeft((x, y) => if (cmp.lteq(f(x), f(y))) x else y) - } - - /** Copies all elements of this $coll to a buffer. - * $willNotTerminateInf - * @param dest The buffer to which elements are copied. - */ - def copyToBuffer[B >: A](dest: Buffer[B]): Unit = dest ++= seq - - def copyToArray[B >: A](xs: Array[B], start: Int): Unit = - copyToArray(xs, start, xs.length - start) - - def copyToArray[B >: A](xs: Array[B]): Unit = - copyToArray(xs, 0, xs.length) - - def toArray[B >: A : ClassManifest]: Array[B] = { - if (isTraversableAgain) { - val result = new Array[B](size) - copyToArray(result, 0) - result - } - else toBuffer.toArray - } - - def toTraversable: Traversable[A] - - def toList: List[A] = new ListBuffer[A] ++= seq toList - - def toIterable: Iterable[A] = toStream - - def toSeq: Seq[A] = toStream - - def toIndexedSeq[B >: A]: immutable.IndexedSeq[B] = immutable.IndexedSeq() ++ seq - - def toBuffer[B >: A]: mutable.Buffer[B] = new ArrayBuffer[B] ++= seq - - def toSet[B >: A]: immutable.Set[B] = immutable.Set() ++ seq - - def toMap[T, U](implicit ev: A <:< (T, U)): immutable.Map[T, U] = { - val b = immutable.Map.newBuilder[T, U] - for (x <- self) - b += x - - b.result - } - - def mkString(start: String, sep: String, end: String): String = - addString(new StringBuilder(), start, sep, end).toString - - def mkString(sep: String): String = mkString("", sep, "") - - def mkString: String = mkString("") - - /** Appends all elements of this $coll to a string builder using start, end, - * and separator strings. - * The written text begins with the string `start` and ends with the string - * `end`. Inside, the string representations (w.r.t. the method `toString`) - * of all elements of this $coll are separated by the string `sep`. - * - * @param b the string builder to which elements are appended. - * @param start the starting string. - * @param sep the separator string. - * @param end the ending string. - * @return the string builder `b` to which elements were appended. - */ - def addString(b: StringBuilder, start: String, sep: String, end: String): StringBuilder = { - var first = true - - b append start - for (x <- self) { - if (first) { - b append x - first = false - } - else { - b append sep - b append x - } - } - b append end - - b - } - - /** Appends all elements of this $coll to a string builder using a separator - * string. The written text consists of the string representations (w.r.t. - * the method `toString`) of all elements of this $coll, separated by the - * string `sep`. - * - * @param b the string builder to which elements are appended. - * @param sep the separator string. - * @return the string builder `b` to which elements were appended. - */ - def addString(b: StringBuilder, sep: String): StringBuilder = addString(b, "", sep, "") - - /** Appends all elements of this $coll to a string builder. - * The written text consists of the string representations (w.r.t. the method - * `toString`) of all elements of this $coll without any separator string. - * - * @param b the string builder to which elements are appended. - * @return the string builder `b` to which elements were appended. - */ - def addString(b: StringBuilder): StringBuilder = addString(b, "") -} - - - diff --git a/src/library/scala/collection/generic/MutableSetFactory.scala b/src/library/scala/collection/generic/MutableSetFactory.scala index 6151da6cb3..6130ef2042 100644 --- a/src/library/scala/collection/generic/MutableSetFactory.scala +++ b/src/library/scala/collection/generic/MutableSetFactory.scala @@ -11,7 +11,7 @@ package generic import mutable.{ Builder, GrowingBuilder } -abstract class MutableSetFactory[CC[X] <: mutable.GenSet[X] with GenSetLike[X, CC[X]]] +abstract class MutableSetFactory[CC[X] <: mutable.Set[X] with mutable.SetLike[X, CC[X]]] extends SetFactory[CC] { def newBuilder[A]: Builder[A, CC[A]] = new GrowingBuilder[A, CC[A]](empty[A]) diff --git a/src/library/scala/collection/immutable/GenIterable.scala b/src/library/scala/collection/immutable/GenIterable.scala.disabled index 217d3f9496..252c721271 100644 --- a/src/library/scala/collection/immutable/GenIterable.scala +++ b/src/library/scala/collection/immutable/GenIterable.scala.disabled @@ -17,21 +17,21 @@ import mutable.Builder /** A base trait for iterable collections that can be mutated. * * $possiblyparinfo - * + * * $iterableInfo */ -trait GenIterable[+A] extends GenTraversable[A] - with scala.collection.GenIterable[A] +trait GenIterable[+A] extends GenTraversable[A] + with scala.collection.GenIterable[A] with scala.collection.GenIterableLike[A, GenIterable[A]] - with GenericTraversableTemplate[A, GenIterable] +// with GenericTraversableTemplate[A, GenIterable] { def seq: Iterable[A] - override def companion: GenericCompanion[GenIterable] = GenIterable + //override def companion: GenericCompanion[GenIterable] = GenIterable } -object GenIterable extends TraversableFactory[GenIterable] { - implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, GenIterable[A]] = new GenericCanBuildFrom[A] - def newBuilder[A]: Builder[A, GenIterable[A]] = Iterable.newBuilder -} +// object GenIterable extends TraversableFactory[GenIterable] { +// implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, GenIterable[A]] = new GenericCanBuildFrom[A] +// def newBuilder[A]: Builder[A, GenIterable[A]] = Iterable.newBuilder +// } diff --git a/src/library/scala/collection/immutable/GenMap.scala b/src/library/scala/collection/immutable/GenMap.scala.disabled index 9dc7242f80..eb7ef2951c 100644 --- a/src/library/scala/collection/immutable/GenMap.scala +++ b/src/library/scala/collection/immutable/GenMap.scala.disabled @@ -19,18 +19,18 @@ import generic._ * @since 1.0 * @author Matthias Zenger */ -trait GenMap[A, +B] +trait GenMap[A, +B] extends GenIterable[(A, B)] - with scala.collection.GenMap[A, B] + with scala.collection.GenMap[A, B] with scala.collection.GenMapLike[A, B, GenMap[A, B]] { def seq: Map[A, B] } -object GenMap extends MapFactory[GenMap] { - def empty[A, B]: Map[A, B] = Map.empty - - /** $mapCanBuildFromInfo */ - implicit def canBuildFrom[A, B]: CanBuildFrom[Coll, (A, B), GenMap[A, B]] = new MapCanBuildFrom[A, B] -} +// object GenMap extends MapFactory[GenMap] { +// def empty[A, B]: Map[A, B] = Map.empty + +// /** $mapCanBuildFromInfo */ +// implicit def canBuildFrom[A, B]: CanBuildFrom[Coll, (A, B), GenMap[A, B]] = new MapCanBuildFrom[A, B] +// } diff --git a/src/library/scala/collection/immutable/GenSeq.scala b/src/library/scala/collection/immutable/GenSeq.scala.disabled index d710954a18..36aff8f8e6 100644 --- a/src/library/scala/collection/immutable/GenSeq.scala +++ b/src/library/scala/collection/immutable/GenSeq.scala.disabled @@ -20,28 +20,28 @@ import mutable.Builder * that can be mutated. * * $possiblyparinfo - * + * * $seqInfo - * + * * The class adds an `update` method to `collection.Seq`. - * + * * @define Coll mutable.Seq * @define coll mutable sequence */ -trait GenSeq[+A] extends GenIterable[A] - with scala.collection.GenSeq[A] +trait GenSeq[+A] extends GenIterable[A] + with scala.collection.GenSeq[A] with scala.collection.GenSeqLike[A, GenSeq[A]] - with GenericTraversableTemplate[A, GenSeq] +// with GenericTraversableTemplate[A, GenSeq] { def seq: Seq[A] - override def companion: GenericCompanion[GenSeq] = GenSeq + //override def companion: GenericCompanion[GenSeq] = GenSeq } -object GenSeq extends SeqFactory[GenSeq] { - implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, GenSeq[A]] = new GenericCanBuildFrom[A] - def newBuilder[A]: Builder[A, GenSeq[A]] = Seq.newBuilder -} +// object GenSeq extends SeqFactory[GenSeq] { +// implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, GenSeq[A]] = new GenericCanBuildFrom[A] +// def newBuilder[A]: Builder[A, GenSeq[A]] = Seq.newBuilder +// } diff --git a/src/library/scala/collection/immutable/GenSet.scala b/src/library/scala/collection/immutable/GenSet.scala.disabled index b222db90f6..3cca6ba66e 100644 --- a/src/library/scala/collection/immutable/GenSet.scala +++ b/src/library/scala/collection/immutable/GenSet.scala.disabled @@ -30,14 +30,14 @@ import mutable.Builder trait GenSet[A] extends GenIterable[A] with scala.collection.GenSet[A] with scala.collection.GenSetLike[A, GenSet[A]] - with GenericSetTemplate[A, GenSet] +// with GenericSetTemplate[A, GenSet] { - override def companion: GenericCompanion[GenSet] = GenSet + //override def companion: GenericCompanion[GenSet] = GenSet def seq: Set[A] } -object GenSet extends TraversableFactory[GenSet] { - implicit def canBuildFrom[A] = new GenericCanBuildFrom[A] - def newBuilder[A] = Set.newBuilder -} +// object GenSet extends TraversableFactory[GenSet] { +// implicit def canBuildFrom[A] = new GenericCanBuildFrom[A] +// def newBuilder[A] = Set.newBuilder +// } diff --git a/src/library/scala/collection/immutable/GenTraversable.scala b/src/library/scala/collection/immutable/GenTraversable.scala.disabled index 69b4d652fb..2ee9bd9d8c 100644 --- a/src/library/scala/collection/immutable/GenTraversable.scala +++ b/src/library/scala/collection/immutable/GenTraversable.scala.disabled @@ -19,23 +19,23 @@ import mutable.Builder /** A trait for traversable collections that can be mutated. * * $possiblyparinfo - * + * * $traversableInfo * @define mutability mutable */ -trait GenTraversable[+A] extends scala.collection.GenTraversable[A] +trait GenTraversable[+A] extends scala.collection.GenTraversable[A] with scala.collection.GenTraversableLike[A, GenTraversable[A]] - with GenericTraversableTemplate[A, GenTraversable] +// with GenericTraversableTemplate[A, GenTraversable] with Mutable { def seq: Traversable[A] - override def companion: GenericCompanion[GenTraversable] = GenTraversable + //override def companion: GenericCompanion[GenTraversable] = GenTraversable } -object GenTraversable extends TraversableFactory[GenTraversable] { - implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, GenTraversable[A]] = new GenericCanBuildFrom[A] - def newBuilder[A]: Builder[A, GenTraversable[A]] = Traversable.newBuilder -} +// object GenTraversable extends TraversableFactory[GenTraversable] { +// implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, GenTraversable[A]] = new GenericCanBuildFrom[A] +// def newBuilder[A]: Builder[A, GenTraversable[A]] = Traversable.newBuilder +// } diff --git a/src/library/scala/collection/immutable/Iterable.scala b/src/library/scala/collection/immutable/Iterable.scala index 411ff38095..81579ef3b7 100644 --- a/src/library/scala/collection/immutable/Iterable.scala +++ b/src/library/scala/collection/immutable/Iterable.scala @@ -22,7 +22,7 @@ import parallel.immutable.ParIterable * @define coll immutable iterable collection */ trait Iterable[+A] extends Traversable[A] - with GenIterable[A] +// with GenIterable[A] with scala.collection.Iterable[A] with GenericTraversableTemplate[A, Iterable] with IterableLike[A, Iterable[A]] diff --git a/src/library/scala/collection/immutable/Map.scala b/src/library/scala/collection/immutable/Map.scala index 90bc63af16..df1cfa80cd 100644 --- a/src/library/scala/collection/immutable/Map.scala +++ b/src/library/scala/collection/immutable/Map.scala @@ -26,7 +26,7 @@ import generic._ * @since 1 */ trait Map[A, +B] extends Iterable[(A, B)] - with GenMap[A, B] +// with GenMap[A, B] with scala.collection.Map[A, B] with MapLike[A, B, Map[A, B]] { self => diff --git a/src/library/scala/collection/immutable/Seq.scala b/src/library/scala/collection/immutable/Seq.scala index 39b99e9e8b..11e56df354 100644 --- a/src/library/scala/collection/immutable/Seq.scala +++ b/src/library/scala/collection/immutable/Seq.scala @@ -23,7 +23,7 @@ import parallel.immutable.ParSeq * @define coll immutable sequence */ trait Seq[+A] extends Iterable[A] - with GenSeq[A] +// with GenSeq[A] with scala.collection.Seq[A] with GenericTraversableTemplate[A, Seq] with SeqLike[A, Seq[A]] diff --git a/src/library/scala/collection/immutable/Set.scala b/src/library/scala/collection/immutable/Set.scala index 63c62d9049..ce2b3b1885 100644 --- a/src/library/scala/collection/immutable/Set.scala +++ b/src/library/scala/collection/immutable/Set.scala @@ -25,7 +25,7 @@ import parallel.immutable.ParSet * @define coll immutable set */ trait Set[A] extends Iterable[A] - with GenSet[A] +// with GenSet[A] with scala.collection.Set[A] with GenericSetTemplate[A, Set] with SetLike[A, Set[A]] diff --git a/src/library/scala/collection/immutable/Traversable.scala b/src/library/scala/collection/immutable/Traversable.scala index 7228642d27..80839db31c 100644 --- a/src/library/scala/collection/immutable/Traversable.scala +++ b/src/library/scala/collection/immutable/Traversable.scala @@ -19,7 +19,7 @@ import mutable.Builder * @define mutability immutable */ trait Traversable[+A] extends scala.collection.Traversable[A] - with GenTraversable[A] +// with GenTraversable[A] with GenericTraversableTemplate[A, Traversable] with TraversableLike[A, Traversable[A]] with Immutable { diff --git a/src/library/scala/collection/mutable/GenIterable.scala b/src/library/scala/collection/mutable/GenIterable.scala.disabled index 60caeb14f9..7fd6a8ca2c 100644 --- a/src/library/scala/collection/mutable/GenIterable.scala +++ b/src/library/scala/collection/mutable/GenIterable.scala.disabled @@ -16,22 +16,22 @@ import generic._ /** A base trait for iterable collections that can be mutated. * * $possiblyparinfo - * + * * $iterableInfo */ -trait GenIterable[A] extends GenTraversable[A] - with scala.collection.GenIterable[A] +trait GenIterable[A] extends GenTraversable[A] + with scala.collection.GenIterable[A] with scala.collection.GenIterableLike[A, GenIterable[A]] - with GenericTraversableTemplate[A, GenIterable] +// with GenericTraversableTemplate[A, GenIterable] { def seq: Iterable[A] - override def companion: GenericCompanion[GenIterable] = GenIterable + //override def companion: GenericCompanion[GenIterable] = GenIterable } -object GenIterable extends TraversableFactory[GenIterable] { - implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, GenIterable[A]] = new GenericCanBuildFrom[A] - def newBuilder[A]: Builder[A, GenIterable[A]] = Iterable.newBuilder -} +// object GenIterable extends TraversableFactory[GenIterable] { +// implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, GenIterable[A]] = new GenericCanBuildFrom[A] +// def newBuilder[A]: Builder[A, GenIterable[A]] = Iterable.newBuilder +// } diff --git a/src/library/scala/collection/mutable/GenMap.scala b/src/library/scala/collection/mutable/GenMap.scala.disabled index 810fa53926..eca63b43ce 100644 --- a/src/library/scala/collection/mutable/GenMap.scala +++ b/src/library/scala/collection/mutable/GenMap.scala.disabled @@ -22,19 +22,19 @@ import generic._ * @since 1.0 * @author Matthias Zenger */ -trait GenMap[A, B] +trait GenMap[A, B] extends GenIterable[(A, B)] - with scala.collection.GenMap[A, B] + with scala.collection.GenMap[A, B] with scala.collection.GenMapLike[A, B, GenMap[A, B]] { def seq: Map[A, B] } -object GenMap extends MapFactory[GenMap] { - def empty[A, B]: Map[A, B] = Map.empty - - /** $mapCanBuildFromInfo */ - implicit def canBuildFrom[A, B]: CanBuildFrom[Coll, (A, B), GenMap[A, B]] = new MapCanBuildFrom[A, B] -} +// object GenMap extends MapFactory[GenMap] { +// def empty[A, B]: Map[A, B] = Map.empty + +// /** $mapCanBuildFromInfo */ +// implicit def canBuildFrom[A, B]: CanBuildFrom[Coll, (A, B), GenMap[A, B]] = new MapCanBuildFrom[A, B] +// } diff --git a/src/library/scala/collection/mutable/GenSeq.scala b/src/library/scala/collection/mutable/GenSeq.scala.disabled index 8e1f727bbb..376a2ceb8b 100644 --- a/src/library/scala/collection/mutable/GenSeq.scala +++ b/src/library/scala/collection/mutable/GenSeq.scala.disabled @@ -19,26 +19,26 @@ import generic._ * that can be mutated. * * $possiblyparinfo - * + * * $seqInfo - * + * * The class adds an `update` method to `collection.Seq`. - * + * * @define Coll mutable.Seq * @define coll mutable sequence */ -trait GenSeq[A] extends GenIterable[A] - with scala.collection.GenSeq[A] +trait GenSeq[A] extends GenIterable[A] + with scala.collection.GenSeq[A] with scala.collection.GenSeqLike[A, GenSeq[A]] - with GenericTraversableTemplate[A, GenSeq] +// with GenericTraversableTemplate[A, GenSeq] { - override def companion: GenericCompanion[GenSeq] = GenSeq + //override def companion: GenericCompanion[GenSeq] = GenSeq def seq: Seq[A] } -object GenSeq extends SeqFactory[GenSeq] { - implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, GenSeq[A]] = new GenericCanBuildFrom[A] - def newBuilder[A]: Builder[A, GenSeq[A]] = Seq.newBuilder -} +// object GenSeq extends SeqFactory[GenSeq] { +// implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, GenSeq[A]] = new GenericCanBuildFrom[A] +// def newBuilder[A]: Builder[A, GenSeq[A]] = Seq.newBuilder +// } diff --git a/src/library/scala/collection/mutable/GenSet.scala b/src/library/scala/collection/mutable/GenSet.scala.disabled index d8f591d0ab..7416577a6a 100644 --- a/src/library/scala/collection/mutable/GenSet.scala +++ b/src/library/scala/collection/mutable/GenSet.scala.disabled @@ -31,16 +31,16 @@ trait GenSet[A] extends GenIterable[A] with Growable[A] with scala.collection.GenSet[A] with scala.collection.GenSetLike[A, GenSet[A]] - with GenericSetTemplate[A, GenSet] +// with GenericSetTemplate[A, GenSet] { - override def companion: GenericCompanion[GenSet] = GenSet + //override def companion: GenericCompanion[GenSet] = GenSet def seq: Set[A] } -object GenSet extends TraversableFactory[GenSet] { - implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, GenSet[A]] = new GenericCanBuildFrom[A] - def newBuilder[A]: Builder[A, GenSet[A]] = Set.newBuilder -} +// object GenSet extends TraversableFactory[GenSet] { +// implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, GenSet[A]] = new GenericCanBuildFrom[A] +// def newBuilder[A]: Builder[A, GenSet[A]] = Set.newBuilder +// } diff --git a/src/library/scala/collection/mutable/GenTraversable.scala b/src/library/scala/collection/mutable/GenTraversable.scala.disabled index b1eec9f471..1ad9bfa9ca 100644 --- a/src/library/scala/collection/mutable/GenTraversable.scala +++ b/src/library/scala/collection/mutable/GenTraversable.scala.disabled @@ -18,21 +18,21 @@ import generic._ /** A trait for traversable collections that can be mutated. * * $possiblyparinfo - * + * * $traversableInfo * @define mutability mutable */ -trait GenTraversable[A] extends scala.collection.GenTraversable[A] +trait GenTraversable[A] extends scala.collection.GenTraversable[A] with scala.collection.GenTraversableLike[A, GenTraversable[A]] - with GenericTraversableTemplate[A, GenTraversable] +// with GenericTraversableTemplate[A, GenTraversable] with Mutable { def seq: Traversable[A] - override def companion: GenericCompanion[GenTraversable] = GenTraversable + //override def companion: GenericCompanion[GenTraversable] = GenTraversable } -object GenTraversable extends TraversableFactory[GenTraversable] { - implicit def canBuildFrom[A] = new GenericCanBuildFrom[A] - def newBuilder[A] = Traversable.newBuilder -} +// object GenTraversable extends TraversableFactory[GenTraversable] { +// implicit def canBuildFrom[A] = new GenericCanBuildFrom[A] +// def newBuilder[A] = Traversable.newBuilder +// } diff --git a/src/library/scala/collection/mutable/Iterable.scala b/src/library/scala/collection/mutable/Iterable.scala index e9ec25ced3..1a5e58b504 100644 --- a/src/library/scala/collection/mutable/Iterable.scala +++ b/src/library/scala/collection/mutable/Iterable.scala @@ -15,7 +15,7 @@ import parallel.mutable.ParIterable * $iterableInfo */ trait Iterable[A] extends Traversable[A] - with GenIterable[A] +// with GenIterable[A] with scala.collection.Iterable[A] with GenericTraversableTemplate[A, Iterable] with IterableLike[A, Iterable[A]] diff --git a/src/library/scala/collection/mutable/Map.scala b/src/library/scala/collection/mutable/Map.scala index e1e6115cfe..561dcc9399 100644 --- a/src/library/scala/collection/mutable/Map.scala +++ b/src/library/scala/collection/mutable/Map.scala @@ -21,7 +21,7 @@ import generic._ */ trait Map[A, B] extends Iterable[(A, B)] - with GenMap[A, B] +// with GenMap[A, B] with scala.collection.Map[A, B] with MapLike[A, B, Map[A, B]] { diff --git a/src/library/scala/collection/mutable/Seq.scala b/src/library/scala/collection/mutable/Seq.scala index d7f50b73ea..42b4ac5c15 100644 --- a/src/library/scala/collection/mutable/Seq.scala +++ b/src/library/scala/collection/mutable/Seq.scala @@ -25,7 +25,7 @@ import generic._ * @define coll mutable sequence */ trait Seq[A] extends Iterable[A] - with GenSeq[A] +// with GenSeq[A] with scala.collection.Seq[A] with GenericTraversableTemplate[A, Seq] with SeqLike[A, Seq[A]] { diff --git a/src/library/scala/collection/mutable/Set.scala b/src/library/scala/collection/mutable/Set.scala index 124af46f76..30fc3682fd 100644 --- a/src/library/scala/collection/mutable/Set.scala +++ b/src/library/scala/collection/mutable/Set.scala @@ -23,7 +23,7 @@ import generic._ * @define coll mutable set */ trait Set[A] extends Iterable[A] - with GenSet[A] +// with GenSet[A] with scala.collection.Set[A] with GenericSetTemplate[A, Set] with SetLike[A, Set[A]] { diff --git a/src/library/scala/collection/mutable/Traversable.scala b/src/library/scala/collection/mutable/Traversable.scala index 64c6fb42d9..b711e0b4db 100644 --- a/src/library/scala/collection/mutable/Traversable.scala +++ b/src/library/scala/collection/mutable/Traversable.scala @@ -18,7 +18,7 @@ import generic._ * @define mutability mutable */ trait Traversable[A] extends scala.collection.Traversable[A] - with GenTraversable[A] +// with GenTraversable[A] with GenericTraversableTemplate[A, Traversable] with TraversableLike[A, Traversable[A]] with Mutable { diff --git a/src/library/scala/collection/parallel/immutable/ParIterable.scala b/src/library/scala/collection/parallel/immutable/ParIterable.scala index 8a03c8a57a..d8c42d74b0 100644 --- a/src/library/scala/collection/parallel/immutable/ParIterable.scala +++ b/src/library/scala/collection/parallel/immutable/ParIterable.scala @@ -30,7 +30,7 @@ import scala.collection.GenIterable * @since 2.9 */ trait ParIterable[+T] -extends collection.immutable.GenIterable[T] +extends collection/*.immutable*/.GenIterable[T] with collection.parallel.ParIterable[T] with GenericParTemplate[T, ParIterable] with ParIterableLike[T, ParIterable[T], collection.immutable.Iterable[T]] diff --git a/src/library/scala/collection/parallel/immutable/ParMap.scala b/src/library/scala/collection/parallel/immutable/ParMap.scala index 5dd4c3f35f..a44a8c965e 100644 --- a/src/library/scala/collection/parallel/immutable/ParMap.scala +++ b/src/library/scala/collection/parallel/immutable/ParMap.scala @@ -38,7 +38,7 @@ import scala.collection.GenMapLike * @since 2.9 */ trait ParMap[K, +V] -extends collection.immutable.GenMap[K, V] +extends collection/*.immutable*/.GenMap[K, V] with GenericParMapTemplate[K, V, ParMap] with parallel.ParMap[K, V] with ParIterable[(K, V)] diff --git a/src/library/scala/collection/parallel/immutable/ParSeq.scala b/src/library/scala/collection/parallel/immutable/ParSeq.scala index 901d4f204d..bf3d3a5aa8 100644 --- a/src/library/scala/collection/parallel/immutable/ParSeq.scala +++ b/src/library/scala/collection/parallel/immutable/ParSeq.scala @@ -28,7 +28,7 @@ import scala.collection.GenSeq * @define coll mutable parallel sequence */ trait ParSeq[+T] -extends collection.immutable.GenSeq[T] +extends collection/*.immutable*/.GenSeq[T] with collection.parallel.ParSeq[T] with ParIterable[T] with GenericParTemplate[T, ParSeq] diff --git a/src/library/scala/collection/parallel/immutable/ParSet.scala b/src/library/scala/collection/parallel/immutable/ParSet.scala index 64fb826d35..a39607ba03 100644 --- a/src/library/scala/collection/parallel/immutable/ParSet.scala +++ b/src/library/scala/collection/parallel/immutable/ParSet.scala @@ -30,7 +30,7 @@ import scala.collection.parallel.Combiner * @define coll mutable parallel set */ trait ParSet[T] -extends collection.immutable.GenSet[T] +extends collection/*.immutable*/.GenSet[T] with GenericParTemplate[T, ParSet] with parallel.ParSet[T] with ParIterable[T] diff --git a/src/library/scala/collection/parallel/mutable/ParIterable.scala b/src/library/scala/collection/parallel/mutable/ParIterable.scala index c07ed69ed5..700d21d0bb 100644 --- a/src/library/scala/collection/parallel/mutable/ParIterable.scala +++ b/src/library/scala/collection/parallel/mutable/ParIterable.scala @@ -26,7 +26,7 @@ import scala.collection.GenIterable * @author Aleksandar Prokopec * @since 2.9 */ -trait ParIterable[T] extends collection.mutable.GenIterable[T] +trait ParIterable[T] extends collection/*.mutable*/.GenIterable[T] with collection.parallel.ParIterable[T] with GenericParTemplate[T, ParIterable] with ParIterableLike[T, ParIterable[T], Iterable[T]] { diff --git a/src/library/scala/collection/parallel/mutable/ParMap.scala b/src/library/scala/collection/parallel/mutable/ParMap.scala index 477e111024..91c2b3d2b2 100644 --- a/src/library/scala/collection/parallel/mutable/ParMap.scala +++ b/src/library/scala/collection/parallel/mutable/ParMap.scala @@ -28,7 +28,7 @@ import collection.parallel.Combiner * @since 2.9 */ trait ParMap[K, V] -extends collection.mutable.GenMap[K, V] +extends collection/*.mutable*/.GenMap[K, V] with collection.parallel.ParMap[K, V] with /* mutable */ ParIterable[(K, V)] with GenericParMapTemplate[K, V, ParMap] diff --git a/src/library/scala/collection/parallel/mutable/ParSeq.scala b/src/library/scala/collection/parallel/mutable/ParSeq.scala index 401e4f900d..a48ba48d56 100644 --- a/src/library/scala/collection/parallel/mutable/ParSeq.scala +++ b/src/library/scala/collection/parallel/mutable/ParSeq.scala @@ -29,7 +29,7 @@ import scala.collection.GenSeq * @define Coll mutable.ParSeq * @define coll mutable parallel sequence */ -trait ParSeq[T] extends collection.mutable.GenSeq[T] // was: collection.mutable.Seq[T] +trait ParSeq[T] extends collection/*.mutable*/.GenSeq[T] // was: collection.mutable.Seq[T] with ParIterable[T] with collection.parallel.ParSeq[T] with GenericParTemplate[T, ParSeq] diff --git a/src/library/scala/collection/parallel/mutable/ParSet.scala b/src/library/scala/collection/parallel/mutable/ParSet.scala index 39e6f827cd..1d295fd5fe 100644 --- a/src/library/scala/collection/parallel/mutable/ParSet.scala +++ b/src/library/scala/collection/parallel/mutable/ParSet.scala @@ -27,7 +27,7 @@ import scala.collection.GenSet * @author Aleksandar Prokopec */ trait ParSet[T] -extends collection.mutable.GenSet[T] +extends collection/*.mutable*/.GenSet[T] with ParIterable[T] with collection.parallel.ParSet[T] with GenericParTemplate[T, ParSet] |