padZip

fun <A, B> Iterable<A>.padZip(other: Iterable<B>): List<Pair<A?, B?>>(source)

Returns a List containing the zipped values of the two lists with null for padding.

import arrow.core.*
import io.kotest.matchers.shouldBe

fun test() {
listOf(1, 2).padZip(listOf("a")) shouldBe listOf(1 to "a", 2 to null)
listOf(1).padZip(listOf("a", "b")) shouldBe listOf(1 to "a", null to "b")
listOf(1, 2).padZip(listOf("a", "b")) shouldBe listOf(1 to "a", 2 to "b")
}

inline fun <A, B, C> Iterable<A>.padZip(other: Iterable<B>, fa: (A?, B?) -> C): List<C>(source)

Returns a List containing the result of applying some transformation (A?, B?) -> C on a zip.

import arrow.core.*
import io.kotest.matchers.shouldBe

fun test() {
listOf(1, 2).padZip(listOf("a")) { l, r -> l to r } shouldBe listOf(1 to "a", 2 to null)
listOf(1).padZip(listOf("a", "b")) { l, r -> l to r } shouldBe listOf(1 to "a", null to "b")
listOf(1, 2).padZip(listOf("a", "b")) { l, r -> l to r } shouldBe listOf(1 to "a", 2 to "b")
}

inline fun <A, B, C> Iterable<A>.padZip(other: Iterable<B>, left: (A) -> C, right: (B) -> C, both: (A, B) -> C): List<C>(source)
fun <K, A, B, C> Map<K, A>.padZip(other: Map<K, B>, fa: (K, A?, B?) -> C): Map<K, C>(source)
inline fun <K, A, B, C> Map<K, A>.padZip(other: Map<K, B>, left: (K, A) -> C, right: (K, B) -> C, both: (K, A, B) -> C): Map<K, C>(source)


fun <A, B> Sequence<A>.padZip(other: Sequence<B>): Sequence<Pair<A?, B?>>(source)

Returns a Sequence> containing the zipped values of the two sequences with null for padding.

Example:

import arrow.core.padZip

//sampleStart
val padRight = sequenceOf(1, 2).padZip(sequenceOf("a")) // Result: [Pair(1, "a"), Pair(2, null)]
val padLeft = sequenceOf(1).padZip(sequenceOf("a", "b")) // Result: [Pair(1, "a"), Pair(null, "b")]
val noPadding = sequenceOf(1, 2).padZip(sequenceOf("a", "b")) // Result: [Pair(1, "a"), Pair(2, "b")]
//sampleEnd

fun main() {
println("padRight = $padRight")
println("padLeft = $padLeft")
println("noPadding = $noPadding")
}

fun <A, B, C> Sequence<A>.padZip(other: Sequence<B>, fa: (A?, B?) -> C): Sequence<C>(source)

Returns a Sequence containing the result of applying some transformation (A?, B?) -> C on a zip.

import arrow.core.padZip

//sampleStart
val padZipRight = sequenceOf(1, 2).padZip(sequenceOf(3)) { l, r -> (l?:0) + (r?:0) } // Result: [4, 2]
val padZipLeft = sequenceOf(1).padZip(sequenceOf(3, 4)) { l, r -> (l?:0) + (r?:0) } // Result: [4, 4]
val noPadding = sequenceOf(1, 2).padZip(sequenceOf(3, 4)) { l, r -> (l?:0) + (r?:0) } // Result: [4, 6]
//sampleEnd

fun main() {
println("padZipRight = $padZipRight")
println("padZipLeft = $padZipLeft")
println("noPadding = $noPadding")
}

fun <K, A, B> Map<K, A>.padZip(other: Map<K, B>): Map<K, Pair<A?, B?>>(source)

Align two structures as in zip, but filling in blanks with null.