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:
35
vendor/github.com/jesseduffield/generics/maps/maps.go
generated
vendored
Normal file
35
vendor/github.com/jesseduffield/generics/maps/maps.go
generated
vendored
Normal 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
|
||||
}
|
Reference in New Issue
Block a user