padZip
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")
}
Content copied to clipboard
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")
}
Content copied to clipboard
inline fun <A, B, C> Iterable<A>.padZip(other: Iterable<B>, left: (A) -> C, right: (B) -> C, both: (A, B) -> C): List<C>
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>
Returns a Sequence
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")
}
Content copied to clipboard
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")
}
Content copied to clipboard
Align two structures as in zip, but filling in blanks with null.