So, I am implementing a POM parser. I've got to the point where I can get all dependencies, but some artifacts may be duplicate with different versions. Like gradle, I want it to just fetch the greater version among those. But in kotlin, I can only see examples of removing duplicates using distinctBy function which does not accept a condition. I wanna filter it by only removing the duplicate entry which has the lowest version and keeping the greater one. How can I do so?
The entries in my list is as follows
data class Artifact(val groupId: String, val artifactId: String, val version: String)
edit: For example, let the list be like
Artifact("com.squareup.okio", "okio-jvm", "3.2.0")
Artifact("org.jetbrains.kotlin", "kotlin-stdlib-jdk8", "1.6.20")
Artifact("org.jetbrains.kotlin", "kotlin-stdlib-common", "1.5.20")
Artifact("org.jetbrains.kotlin", "kotlin-stdlib-common", "1.6.21")
Artifact("org.jetbrains", "annotations", "13.0")
And the output is expected to be like
Artifact("com.squareup.okio", "okio-jvm", "3.2.0")
Artifact("org.jetbrains.kotlin", "kotlin-stdlib-jdk8", "1.6.20")
Artifact("org.jetbrains.kotlin", "kotlin-stdlib-common", "1.6.21")
Artifact("org.jetbrains", "annotations", "13.0")
i.e, to remove the version that is the lowest among the duplicates