music: fix broken name comparator
This commit is contained in:
parent
6e07b3fcfd
commit
24dbd04ca6
1 changed files with 2 additions and 3 deletions
|
@ -70,12 +70,11 @@ sealed interface Name : Comparable<Name> {
|
||||||
final override fun compareTo(other: Name) =
|
final override fun compareTo(other: Name) =
|
||||||
when (other) {
|
when (other) {
|
||||||
is Known -> {
|
is Known -> {
|
||||||
// Progressively compare the sort tokens between each known name.
|
val result = sortTokens.zip(other.sortTokens).fold(0) { acc, (token, otherToken) ->
|
||||||
sortTokens.zip(other.sortTokens).fold(0) { acc, (token, otherToken) ->
|
|
||||||
acc.takeIf { it != 0 } ?: token.compareTo(otherToken)
|
acc.takeIf { it != 0 } ?: token.compareTo(otherToken)
|
||||||
}
|
}
|
||||||
|
if (result != 0) result else sortTokens.size.compareTo(other.sortTokens.size)
|
||||||
}
|
}
|
||||||
// Unknown names always come before known names.
|
|
||||||
is Unknown -> 1
|
is Unknown -> 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue