arrow-core-data / arrow.core / kotlin.collections.Iterable / rightPadZip

rightPadZip

inline fun <A, B, C> Iterable<A>.rightPadZip(other: Iterable<B>, fa: (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 left value is null.

Example:

import arrow.core.*

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

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

Returns a ListPairA,B? containing the zipped values of the two lists with null for padding on the right.

Example:

import arrow.core.*

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

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

Do you like Arrow?

Arrow Org
<