Port theme loading code to Go

This commit is contained in:
Kovid Goyal
2023-02-26 20:40:59 +05:30
parent 4eea2fd4fc
commit 0b09d18b36
2 changed files with 204 additions and 0 deletions

View File

@@ -57,6 +57,14 @@ func Filter[T any](s []T, f func(x T) bool) []T {
return ans
}
func Map[T any](s []T, f func(x T) T) []T {
ans := make([]T, 0, len(s))
for _, x := range s {
ans = append(ans, f(x))
}
return ans
}
func Sort[T any](s []T, less func(a, b T) bool) []T {
sort.Slice(s, func(i, j int) bool { return less(s[i], s[j]) })
return s