1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-23 00:39:13 +02:00

lots more generics

This commit is contained in:
Jesse Duffield
2022-03-19 15:36:46 +11:00
parent c7a629c440
commit eda8f4a5d4
19 changed files with 384 additions and 299 deletions

35
vendor/github.com/jesseduffield/generics/maps/maps.go generated vendored Normal file
View File

@ -0,0 +1,35 @@
package maps
func Keys[Key comparable, Value any](m map[Key]Value) []Key {
keys := make([]Key, 0, len(m))
for key := range m {
keys = append(keys, key)
}
return keys
}
func Values[Key comparable, Value any](m map[Key]Value) []Value {
values := make([]Value, 0, len(m))
for _, value := range m {
values = append(values, value)
}
return values
}
func TransformValues[Key comparable, Value any, NewValue any](
m map[Key]Value, fn func(Value) NewValue,
) map[Key]NewValue {
output := make(map[Key]NewValue)
for key, value := range m {
output[key] = fn(value)
}
return output
}
func TransformKeys[Key comparable, Value any, NewKey comparable](m map[Key]Value, fn func(Key) NewKey) map[NewKey]Value {
output := make(map[NewKey]Value)
for key, value := range m {
output[fn(key)] = value
}
return output
}