mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-13 01:30:53 +02:00
more generics
This commit is contained in:
18
vendor/github.com/jesseduffield/generics/maps/maps.go
generated
vendored
18
vendor/github.com/jesseduffield/generics/maps/maps.go
generated
vendored
@ -33,3 +33,21 @@ func TransformKeys[Key comparable, Value any, NewKey comparable](m map[Key]Value
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
||||
func MapToSlice[Key comparable, Value any, Mapped any](m map[Key]Value, f func(Key, Value) Mapped) []Mapped {
|
||||
output := make([]Mapped, 0, len(m))
|
||||
for key, value := range m {
|
||||
output = append(output, f(key, value))
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
||||
func Filter[Key comparable, Value any](m map[Key]Value, f func(Key, Value) bool) map[Key]Value {
|
||||
output := map[Key]Value{}
|
||||
for key, value := range m {
|
||||
if f(key, value) {
|
||||
output[key] = value
|
||||
}
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
Reference in New Issue
Block a user