joinByKey

Performs a join between two sorted sequences 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.joinByKey(seq2) { _, v1, v2 -> "${v1 ?: ""}${v2 ?: ""}" }
assertEquals(
listOf("1a", "2b2x", "2b2y", "2c2x", "2c2y", "3z"),
result.toList()
)

Return

A new sorted sequence with merged values according to the join type

Parameters

other

The sequence to join with

joinType

The type of join to perform (INNER_JOIN, LEFT_OUTER_JOIN, RIGHT_OUTER_JOIN, FULL_OUTER_JOIN)

mergeFn

Function that defines how to merge values for matching keys


Performs a join between two sorted sequences based on matching keys 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.joinByKey(seq2)
assertEquals(
listOf(
"1a" to null,
"2b" to "2x",
"2b" to "2y",
"2c" to "2x",
"2c" to "2y",
null to "3z"
),
result.toList()
)

Return

A new sorted sequence with paired values according to the join type

Parameters

other

The sequence to join with

joinType

The type of join to perform (default: FULL_OUTER_JOIN)