join By Key
fun <TValue2, TValueOut> joinByKey(other: SortedKeyValueIteratorProvider<TKey, TValue2>, joinType: JoinType = FULL_OUTER_JOIN, mergeFn: (TKey, TValue?, TValue2?) -> TValueOut): SortedKeyValueSequence<TKey, TValueOut>
Performs a join between two sorted sequences 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.joinByKey(seq2) { _, v1, v2 -> "${v1 ?: ""}${v2 ?: ""}" }
assertEquals(
listOf(
1 to "a",
2 to "bx",
2 to "by",
2 to "cx",
2 to "cy",
3 to "z"
),
result2.toList()
)
Content copied to clipboard
Return
A new sorted sequence with merged values according to the join type
Parameters
other
The sequence to join with
join Type
The type of join to perform (INNER_JOIN, LEFT_OUTER_JOIN, RIGHT_OUTER_JOIN, FULL_OUTER_JOIN)
merge Fn
Function that defines how to merge values for matching keys
fun <TValue2> joinByKey(other: SortedKeyValueIteratorProvider<TKey, TValue2>, joinType: JoinType = FULL_OUTER_JOIN): SortedKeyValueSequence<TKey, Pair<TValue?, TValue2?>>
Performs a join between two sorted sequences 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.joinByKey(seq2)
assertEquals(
listOf(
1 to ("a" to null),
2 to ("b" to "x"),
2 to ("b" to "y"),
2 to ("c" to "x"),
2 to ("c" to "y"),
3 to (null to "z")
),
result.toList()
)
Content copied to clipboard
Return
A new sorted sequence with paired values according to the sort type
Parameters
other
The sequence to join with
join Type
The type of join to perform (default: FULL_OUTER_JOIN)