fix tracklist selection being maintained when sorting

This commit is contained in:
Drew Weymouth
2023-06-02 17:43:22 -07:00
parent 8b238fd239
commit b64dcdcc0b
5 changed files with 182 additions and 71 deletions
+14 -2
View File
@@ -40,15 +40,19 @@ func MapSlice[T any, U any](ts []T, f func(T) U) []U {
return result
}
func IndexOf[T comparable](ts []T, t T) int {
func Find[T any](ts []T, f func(T) bool) int {
for i, tt := range ts {
if t == tt {
if f(tt) {
return i
}
}
return -1
}
func IndexOf[T comparable](ts []T, t T) int {
return Find(ts, func(tt T) bool { return t == tt })
}
func Reversed[T any](ts []T) []T {
if ts == nil {
return nil
@@ -62,6 +66,14 @@ func Reversed[T any](ts []T) []T {
return new
}
func ToSet[T comparable](ts []T) map[T]interface{} {
set := make(map[T]interface{}, len(ts))
for _, t := range ts {
set[t] = nil
}
return set
}
func FindTrackByID(id string, tracks []*mediaprovider.Track) *mediaprovider.Track {
for _, tr := range tracks {
if id == tr.ID {