//arrow-core/arrow.core/leftPadZip

leftPadZip

common inline fun <A, B, C> Iterable<A>.leftPadZip(other: Iterable<B>, fab: (A?, B) -> C): List<C>

Returns a List 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).leftPadZip(listOf("a")) { l, r -> l to r }      // Result: [Pair(1, "a")]
val right = listOf(1).leftPadZip(listOf("a", "b")) { l, r -> l to r }   // Result: [Pair(1, "a"), Pair(null, "b")]
val both = listOf(1, 2).leftPadZip(listOf("a", "b")) { l, r -> l to r } // Result: [Pair(1, "a"), Pair(2, "b")]
//sampleEnd

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

common fun <A, B> Iterable<A>.leftPadZip(other: Iterable<B>): List<Pair<A?, B»

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

Example:

import arrow.core.*

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

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

common fun <A, B, C> Sequence<A>.leftPadZip(other: Sequence<B>, fab: (A?, B) -> C): Sequence<C>

Returns a Sequence 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.leftPadZip

//sampleStart
val left = sequenceOf(1, 2).leftPadZip(sequenceOf(3)) { l, r -> l?.plus(r) ?: r }    // Result: [4]
val right = sequenceOf(1).leftPadZip(sequenceOf(3, 4)) { l, r -> l?.plus(r) ?: r }   // Result: [4, 4]
val both = sequenceOf(1, 2).leftPadZip(sequenceOf(3, 4)) { l, r -> l?.plus(r) ?: r } // Result: [4, 6]
//sampleEnd

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

common fun <A, B> Sequence<A>.leftPadZip(other: Sequence<B>): Sequence<Pair<A?, B»

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

Example:

import arrow.core.leftPadZip

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

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

Do you like Arrow?

Arrow Org
<