6

Say, i am looking to better understand what reduceLeft method does when applied on a Array[String]

The scaladoc says: enter image description here

Ok, i must ask again, what does this method do? And what's more important, if i can't rely on scaladoc to tell me that, where can i find out?

James Raitsev
  • 92,517
  • 154
  • 335
  • 470
  • 3
    To avoid others wasting their time... there's no significant info in ArrayOps, IndexSeqOptimized, or TraversableOnce, either. And this is one of the most fundamental collection operations! This kind of reference-doc issue is one of the most infuriating things about Scala. – Ed Staub Jan 07 '13 at 00:42
  • 2
    [Bug reported](https://issues.scala-lang.org/browse/SI-6930), now go vote for it, will you ? – Francois G Jan 07 '13 at 10:42
  • Fixed : https://github.com/scala/scala/pull/1860 – Francois G Jan 15 '13 at 07:52

1 Answers1

8

Yeah - that Scaladoc entry could probably be more helpful.

Another useful source of documentation is the Scala Documentation site, which has this to say about reduceLeft:

xs reduceLeft op

Apply binary operation op between successive elements of non-empty collection xs, going left to right.

So what it does is reduce a collection to a single value by successively applying a binary operator. Some examples:

scala> Array(1, 2, 3, 4) reduceLeft (_ + _)
res2: Int = 10

scala> Array("foo", "bar", "baz") reduceLeft (_ + _)
res3: String = foobarbaz
Paul Butcher
  • 10,722
  • 3
  • 40
  • 44