music: fix broken name comparator

This commit is contained in:
Alexander Capehart 2024-07-10 06:51:32 -06:00
parent 6e07b3fcfd
commit 24dbd04ca6
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47

View file

@ -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
} }