zip By Key
fun <TValue2, TValueOut> zipByKey(other: SortedKeyValueIteratorProvider<TKey, TValue2>, joinType: JoinType = FULL_OUTER_JOIN, mergeFn: (TKey, TValue?, TValue2?) -> TValueOut): SortedSequence<TKey, TValueOut>
Zips the sequence with another sorted sequence based on matching keys.
Example:
val seq1 = sequenceOf("1a", "2b", "2c").assertSortedBy { it.first() }
val seq2 = sequenceOf("2x", "2y", "3z").assertSortedBy { it.first() }
val result = seq1.zipByKey(seq2) { _, v1, v2 -> "${v1 ?: ""}${v2 ?: ""}" }
assertEquals(
listOf("1a", "2b2x", "2c2y", "3z"),
result.toList()
)
Content copied to clipboard
Return
A new sorted sequence with merged values
Parameters
other
The sequence to merge with
join Type
The type of join to perform (default: FULL_OUTER_JOIN)
merge Fn
Function that defines how to merge values for matching keys
fun <TValue2> zipByKey(other: SortedKeyValueIteratorProvider<TKey, TValue2>, joinType: JoinType = FULL_OUTER_JOIN): SortedSequence<TKey, Pair<TValue?, TValue2?>>
Zips the sequence with another sorted sequence using default pairing of values.
Example:
val seq1 = sequenceOf("1a", "2b", "2c").assertSortedBy { it.first() }
val seq2 = sequenceOf("2x", "2y", "3z").assertSortedBy { it.first() }
val result = seq1.zipByKey(seq2)
assertEquals(
listOf(
"1a" to null,
"2b" to "2x",
"2c" to "2y",
null to "3z"
),
result.toList()
)
Content copied to clipboard
Return
A new sorted sequence with paired values
Parameters
other
The sequence to merge with
join Type
The type of join to perform (default: FULL_OUTER_JOIN)