Finding Scaladoc help, reduceLeft
Asked Answered
M

1

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?

Mordacious answered 7/1, 2013 at 0:24 Comment(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.Maltzman
Bug reported, now go vote for it, will you ?Preparator
Fixed : github.com/scala/scala/pull/1860Preparator
C
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
Cadastre answered 7/1, 2013 at 0:46 Comment(1)
what is as binary operation?Lackluster

© 2022 - 2024 — McMap. All rights reserved.