arrow-core-data / arrow.core / ListK / leftPadZip

leftPadZip

fun <B, C> leftPadZip(other: ListK<B>, fab: (A?, B) -> C): ListK<C>

Returns a ListK containing the result of applying some transformation (A?, B) -> C on a zip, excluding all cases where the right value is null.

Example:

import arrow.core.*

//sampleStart
val left = listOf(1, 2).k().leftPadZip(listOf("a").k()) { l, r -> l toT r }.k()      // Result: ListK(Tuple2(1, "a"))
val right = listOf(1).k().leftPadZip(listOf("a", "b").k()) { l, r -> l toT r }.k()   // Result: ListK(Tuple2(1, "a"), Tuple2(null, "b"))
val both = listOf(1, 2).k().leftPadZip(listOf("a", "b").k()) { l, r -> l toT r }.k() // Result: ListK(Tuple2(1, "a"), Tuple2(2, "b"))
//sampleEnd

fun main() {
  println("left = $left")
  println("right = $right")
  println("both = $both")
}

fun <B> leftPadZip(other: ListK<B>): ListK<Tuple2<A?, B>>

Returns a ListKTuple2A?,B containing the zipped values of the two listKs with null for padding on the left.

Example:

import arrow.core.*

//sampleStart
val padRight = listOf(1, 2).k().leftPadZip(listOf("a").k())        // Result: ListK(Tuple2(1, "a"))
val padLeft = listOf(1).k().leftPadZip(listOf("a", "b").k())       // Result: ListK(Tuple2(1, "a"), Tuple2(null, "b"))
val noPadding = listOf(1, 2).k().leftPadZip(listOf("a", "b").k())  // Result: ListK(Tuple2(1, "a"), Tuple2(2, "b"))
//sampleEnd

fun main() {
  println("left = $left")
  println("right = $right")
  println("both = $both")
}

Do you like Arrow?

Arrow Org
<