Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding Scaladoc help, reduceLeft

Tags:

scala

scaladoc

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?

like image 399
James Raitsev Avatar asked Jan 07 '13 00:01

James Raitsev


1 Answers

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
like image 189
Paul Butcher Avatar answered Sep 24 '22 18:09

Paul Butcher