Hello,
According the API doc fold is following: fun <T> fold(initial: T, operation: (T, T) -> T): T
In my mind such signature is quite restrictive. For example, if I have an array/list of characters (word) and I want to calculate characters occurrence in the word, in kotlin I cannot accomplish such task using fold, in scala I can.
Scala fold signature is kind of def foldLeft[B](z : B)(f : scala.Function2[B, A, B]) : B
And to get characters occurrence (as map) I could write: chars.foldLeft(Map())((m, ch) => m.updated(ch, m.getOrElse(ch, {0}) + 1))
Wouldn’t it be better (if possible) to make fold signature similar to Scala one?
Regards,
Vadim