37 lines
847 B
Go
37 lines
847 B
Go
package main
|
|
|
|
import (
|
|
"sort"
|
|
|
|
"git.milar.in/milarin/tprint"
|
|
"git.milar.in/nyaanime/model"
|
|
)
|
|
|
|
func Map2Table[K comparable](title string, m map[K]int) string {
|
|
table := tprint.NewTable(title, "priority")
|
|
|
|
entries := make([]model.Pair[K, int], 0, len(m))
|
|
for name, priority := range m {
|
|
entries = append(entries, model.Pair[K, int]{First: name, Second: priority})
|
|
}
|
|
sort.Slice(entries, func(i, j int) bool { return entries[i].Second > entries[j].Second })
|
|
|
|
for _, entry := range entries {
|
|
table.AddRow(entry.First, entry.Second)
|
|
}
|
|
|
|
return table.String()
|
|
}
|
|
|
|
func GetAnimeEpisodesSortFunc(s []model.AnimeEpisode) func(i, j int) bool {
|
|
return func(i, j int) bool {
|
|
if s[i].Anime.ID < s[j].Anime.ID {
|
|
return true
|
|
} else if s[i].Anime.ID > s[j].Anime.ID {
|
|
return false
|
|
} else {
|
|
return s[i].Episode <= s[j].Episode
|
|
}
|
|
}
|
|
}
|