Hello, Does Kotlin have a `scanRight`, a symmetry...
# getting-started
x
Hello, Does Kotlin have a
scanRight
, a symmetry of
scan
, starting by the end of the collection, to be consistent with the availability of fold(Right) and reduce(Right)? Something like
Copy code
inline fun <R> List<R>.scanRight(initial: R, operation: (acc: R, Int) -> R): List<R>
So I don't need to use
.reversed()
twice to achieve the same with the (left)
scan()
that we have like this:
Copy code
listOf(whatever).reversed().scan(0){acc, e -> operation...}.reversed()
s
Doesn't look like it: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/ 🤷‍♂️ Maybe you can build it yourself as extension function using foldRight?
a
A related hint: there's
asReversed()
, which should mitigate needing to reverse the list twice https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/as-reversed.html
💯 1
👍 1
x
I didn't this one, nice, thanks 🙂