zipByKey

Zips this sequence with another sorted sequence based on matching keys.

Example:

val seq1 = sequenceOf(1 to "a", 2 to "b", 2 to "c").assertSorted()
val seq2 = sequenceOf(2 to "x", 2 to "y", 3 to "z").assertSorted()
val result = seq1.zipByKey(seq2) { _, v1, v2 -> "${v1 ?: ""}${v2 ?: ""}" }
assertEquals(
listOf(
1 to "a",
2 to "bx",
2 to "cy",
3 to "z"
),
result2.toList()
)

Return

A new sorted sequence with merged values

Parameters

other

The sequence to zip with

joinType

The type of join to perform (default: FULL_OUTER_JOIN)

mergeFn

Function that defines how to merge values for matching keys


Zips the sequence with another sorted sequence using default pairing of values.

Example:

val seq1 = sequenceOf(1 to "a", 2 to "b", 2 to "c").assertSorted()
val seq2 = sequenceOf(2 to "x", 2 to "y", 3 to "z").assertSorted()
val result = seq1.zipByKey(seq2)
assertEquals(
listOf(
1 to ("a" to null),
2 to ("b" to "x"),
2 to ("c" to "y"),
3 to (null to "z")
),
result.toList()
)

Return

A new sorted sequence with paired values

Parameters

other

The sequence to merge with

joinType

The type of join to perform (default: FULL_OUTER_JOIN)