Handle "naked" CoverArtIDs (IDs of album, mediafiles and playlists)

This commit is contained in:
Deluan
2022-12-28 12:32:46 -05:00
committed by Deluan Quintão
parent bc09de6640
commit 61e5523457
14 changed files with 82 additions and 25 deletions
+8
View File
@@ -1,5 +1,13 @@
package slice
func Map[T any, R any](t []T, mapFunc func(T) R) []R {
r := make([]R, len(t))
for i, e := range t {
r[i] = mapFunc(e)
}
return r
}
func Group[T any, K comparable](s []T, keyFunc func(T) K) map[K][]T {
m := map[K][]T{}
for _, item := range s {
+15
View File
@@ -1,6 +1,7 @@
package slice_test
import (
"strconv"
"testing"
"github.com/navidrome/navidrome/utils/slice"
@@ -13,6 +14,20 @@ func TestSlice(t *testing.T) {
RunSpecs(t, "Slice Suite")
}
var _ = Describe("Map", func() {
It("returns empty slice for an empty input", func() {
mapFunc := func(v int) string { return strconv.Itoa(v * 2) }
result := slice.Map([]int{}, mapFunc)
Expect(result).To(BeEmpty())
})
It("returns a new slice with elements mapped", func() {
mapFunc := func(v int) string { return strconv.Itoa(v * 2) }
result := slice.Map([]int{1, 2, 3, 4}, mapFunc)
Expect(result).To(ConsistOf("2", "4", "6", "8"))
})
})
var _ = Describe("Group", func() {
It("returns empty map for an empty input", func() {
keyFunc := func(v int) int { return v % 2 }