summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorschinz <schinz@epfl.ch>2003-04-08 07:58:39 +0000
committerschinz <schinz@epfl.ch>2003-04-08 07:58:39 +0000
commita715104520d600e7cb57a484b89ce0a5510770f0 (patch)
treee89a35f7188c70ff5aaeeb43e10903b90e66026e /sources
parentfae0e93a6aede02f539fa5acd3a0f5267dbbd5c7 (diff)
downloadscala-a715104520d600e7cb57a484b89ce0a5510770f0.tar.gz
scala-a715104520d600e7cb57a484b89ce0a5510770f0.tar.bz2
scala-a715104520d600e7cb57a484b89ce0a5510770f0.zip
- adapted to the new names for fold and reduce
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/List.scala31
1 files changed, 15 insertions, 16 deletions
diff --git a/sources/scala/List.scala b/sources/scala/List.scala
index 36ccf54451..4ed3044776 100644
--- a/sources/scala/List.scala
+++ b/sources/scala/List.scala
@@ -176,35 +176,34 @@ trait List[a] extends Seq[a] {
/** Combines the elements of this list together using the binary
* operator <code>op</code>, from left to right, and starting with
- * the value <code>z</code>. Similar to <code>fold</code> but with
- * a different order of the arguments, allowing to use nice constructions like
- * <code>(z foldl_: l) { ... }</code>.
+ * the value <code>z</code>.
* @return <code>op(... (op(op(z,a0),a1) ...), an)</code> if the list
* is <code>[a0, a1, ..., an]</code>.
*/
- def foldl_:[b](z: b)(f: (b, a) => b): b = match {
+ def foldLeft[b](z: b)(f: (b, a) => b): b = match {
case Nil => z
- case x :: xs => (xs.foldl_:[b](f(z, x)))(f)
+ case x :: xs => xs.foldLeft[b](f(z, x))(f)
}
- def foldr[b](z: b)(f: (a, b) => b): b = match {
+ def foldRight[b](z: b)(f: (a, b) => b): b = match {
case Nil => z
- case x :: xs => f(x, (xs foldr z)(f))
+ case x :: xs => f(x, xs.foldRight(z)(f))
}
- def foldl1(f: (a, a) => a): a = this match {
- case Nil => error("foldl1 of empty list")
- case x :: xs => (x foldl_: xs)(f)
+ def reduceLeft(f: (a, a) => a): a = this match {
+ case Nil => error("reduceLeft of empty list")
+ case x :: xs => xs.foldLeft(x)(f)
}
- def foldr1(f: (a, a) => a): a = match {
- case Nil => error("foldr1 of empty list")
+ def reduceRight(f: (a, a) => a): a = match {
+ case Nil => error("reduceRight of empty list")
case x :: Nil => x
- case x :: xs => f(x, xs foldr1 f)
+ case x :: xs => xs.foldRight(x)(f)
}
- /** Applies the given function <code>f</code> to each element of this list, then concatenates
- * the results.
+ /**
+ * Applies the given function <code>f</code> to each element of
+ * this list, then concatenates the results.
* @param f the function to apply on each element.
* @return <code>f(a0) ::: ... ::: f(an)</code> if this list is
* <code>[a0, ..., an]</code>.
@@ -220,7 +219,7 @@ trait List[a] extends Seq[a] {
* @return the elements of this list in reverse order.
*/
def reverse: List[a] = {
- ((Nil: List[a]) foldl_: this)((xs: List[a], x: a) => x :: xs)
+ foldLeft(Nil: List[a])((xs: List[a], x: a) => x :: xs)
}
/** Prints on standard output a raw textual representation of this list.