Say, i am looking to better understand what reduceLeft
method does when applied on a Array[String]
The scaladoc says:
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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With