Use maps package for generic keys/values functions
This commit is contained in:
parent
7ce83e7fd0
commit
3803d7e3c2
@ -8,6 +8,8 @@ import (
|
||||
|
||||
"kitty/tools/cli/markup"
|
||||
"kitty/tools/utils"
|
||||
|
||||
"golang.org/x/exp/maps"
|
||||
)
|
||||
|
||||
var _ = fmt.Print
|
||||
@ -21,7 +23,7 @@ func fish_completion_script(commands []string) (string, error) {
|
||||
"kitten": true,
|
||||
}
|
||||
if len(commands) == 0 {
|
||||
commands = append(commands, utils.Keys(all_commands)...)
|
||||
commands = append(commands, maps.Keys(all_commands)...)
|
||||
}
|
||||
script := strings.Builder{}
|
||||
script.WriteString(`function __ksi_completions
|
||||
|
||||
@ -17,6 +17,7 @@ import (
|
||||
"kitty/tools/utils"
|
||||
"kitty/tools/utils/images"
|
||||
|
||||
"golang.org/x/exp/maps"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
@ -363,7 +364,7 @@ func run_get_loop(opts *Options, args []string) (err error) {
|
||||
}
|
||||
}
|
||||
if len(requested_mimes) > 0 {
|
||||
lp.QueueWriteString(encode(basic_metadata, strings.Join(utils.Keys(requested_mimes), " ")))
|
||||
lp.QueueWriteString(encode(basic_metadata, strings.Join(maps.Keys(requested_mimes), " ")))
|
||||
} else {
|
||||
lp.Quit(0)
|
||||
}
|
||||
|
||||
@ -120,30 +120,6 @@ func Min[T constraints.Ordered](a T, items ...T) (ans T) {
|
||||
return ans
|
||||
}
|
||||
|
||||
// Keys returns the keys of the map m.
|
||||
// The keys will be an indeterminate order.
|
||||
func Keys[M ~map[K]V, K comparable, V any](m M) []K {
|
||||
r := make([]K, len(m))
|
||||
i := 0
|
||||
for k := range m {
|
||||
r[i] = k
|
||||
i++
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// Values returns the values of the map m.
|
||||
// The values will be an indeterminate order.
|
||||
func Values[M ~map[K]V, K comparable, V any](m M) []V {
|
||||
r := make([]V, len(m))
|
||||
i := 0
|
||||
for _, v := range m {
|
||||
r[i] = v
|
||||
i++
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func Memset[T any](dest []T, pattern ...T) []T {
|
||||
if len(pattern) == 0 {
|
||||
var zero T
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user