Is there a more elegant way to do this with the Ko...
# codereview
n
Is there a more elegant way to do this with the Kotlin standard lib?
Copy code
val values = listOf("name", "ASC", "description", "DESC")
val propNames = values.filterIndexed { index, _ -> index.mod(2) == 0 }
val sortDirections = values.filterIndexed { index, _ -> index.mod(2) != 0 }
propNames zip sortDirections // [(name, ASC), (description, DESC)]
e
Copy code
values.chunked(2) { (k, v) -> k to v }
or
.windowed(2, 2)
if you want to ignore odd-length inputs instead of crashing
2
👌 4
n
oh nice! I forgot about chunked, but I didn't know windowed existed.