Is there a function in Scala, which is a hybrid of map and fold? I'd like not to use a temporary var variable. I want to return a list and at the same time be able to have an accumulator.
update:
I'd like to do this
def findMaxSubarray(source: Seq[Int]) = {
var lastSum = 0
val maxes = source map { x =>
lastSum += x
if (lastSum < 0) lastSum = 0
lastSum
}
maxes.max
}
without using scalaz
and var
, only using standard scala library.