Just as `fold` and `reduce` have `foldRight`, `red...
# stdlib
h
Just as
fold
and
reduce
have
foldRight
,
reduceRight
, I would like
windowedRight
and
chunkedRight
. My current use case is also maybe the best example:
Copy code
val Int.digitBlocks get() = toString().chunkedRight(3).map(String::toInt) // 1_234_567 -> [[567], [234], [1]]
I noticed
CharSequence
also has a version of
windowed
that accepts a transform operation, and I would like that for
Iterable
as well. In general why don't most Iterable operations also have a version with a transform operation tacked on? I don't think that hurts readability, and only partially conflicts in places where the operation already receives a lambda, like
partition
z
Can you get the same thing by just calling
asReversed()
first?
h
That would return
[[765], [432], [1]]
in my example; the contents of each chunk are also reversed
so
asReversed().chunked(3).map { it.asReversed().toInt() }
would work
z
oh right, that wouldn’t work for chunking/windowing, duh