More work on porting diff kitten

This commit is contained in:
Kovid Goyal
2023-03-20 17:21:53 +05:30
parent 4f5fc1000d
commit 1c7d1094d4
3 changed files with 259 additions and 10 deletions

View File

@@ -66,6 +66,14 @@ func Map[T any, O any](f func(x T) O, s []T) []O {
return ans
}
func Repeat[T any](x T, n int) []T {
ans := make([]T, n)
for i := 0; i < n; i++ {
ans[i] = 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