Created
November 30, 2020 17:04
-
-
Save kjkrol/06de30a26bf24ee30262c266b0c96da8 to your computer and use it in GitHub Desktop.
Inner Join
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun <T : Any, U : Any> Collection<T>.innerJoin( | |
with: Collection<U>, | |
on: (Pair<T, U>) -> Boolean | |
): Collection<Pair<T, U>> = map { t -> | |
val intersection = with.filter { on(Pair(t, it)) } | |
Pair(t, intersection) | |
} | |
.filter { pair -> pair.second.isNotEmpty() } | |
.flatMap { pair -> pair.second.map { Pair(pair.first, it) } } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment