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.

Example:

import arrow.core.*

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

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

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.

Example:

import arrow.core.*

//sampleStart
val padZipRight = listOf(1, 2).padZip(listOf("a")) { l, r -> l to r } // Result: [Pair(1, "a"), Pair(2, null)]
val padZipLeft = listOf(1).padZip(listOf("a", "b")) { l, r -> l to r } // Result: [Pair(1, "a"), Pair(null, "b")]
val noPadding = listOf(1, 2).padZip(listOf("a", "b")) { l, r -> l to r } // Result: [Pair(1, "a"), Pair(2, "b")]
//sampleEnd

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

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.

Example:

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.


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