Hi all, whats the stdlib way to achieve this? ```v...
# stdlib
x
Hi all, whats the stdlib way to achieve this?
Copy code
val actual = listOf("a","b","c","d")
val expected = listOf("ab","bc","cd")
e
actual.windowed(2) { it.joinToString("") }
d
Windowed accepts a transformation function , no need to map
e
fix'd
d
:)
x
also found out this is a thing
Copy code
actual.zipWithNext { a, b -> "$a$b" }
👍🏼 1
👌 3
👍 2
d
Yeah. Zip with next is limited to only chunks of 2, which is fine in this case but is somewhat limiting and it actually creates a list of Pair as opposed to a list of list. Nothing wrong with that approach though
👍 1
s
If you want list of lists, you would just do
Copy code
list.zipWithNext() {a, b -> listOf(a, b)}
but i see @xxfast probably figured this out.