Proposal to add `zipWithNull` (as seen on <#C87V9M...
# language-proposals
x
Proposal to add
zipWithNull
(as seen on #advent-of-code)
Copy code
fun <T, R> Iterable<T>.zipWithNull(other: Iterable<R>): List<Pair<T?, R?>> = buildList {
  val first = this@zipWithNull.iterator()
  val second = other.iterator()
  while (first.hasNext() || second.hasNext()) {
    val left = if (first.hasNext()) first.next() else null
    val right = if (second.hasNext()) second.next() else null
    add(left to right)
  }
}
s
There has been a proposal for a more universal function like this for a long time.
zipAll
as know from some other languages. https://youtrack.jetbrains.com/issue/KT-13017
👀 2