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

more generics

This commit is contained in:
Jesse Duffield
2022-03-19 16:34:46 +11:00
parent eda8f4a5d4
commit bf4f06ab4e
21 changed files with 303 additions and 198 deletions

View File

@ -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
}

View File

@ -19,13 +19,9 @@ func NewFromSlice[T comparable](slice []T) *Set[T] {
return &Set[T]{hashMap: hashMap}
}
func (s *Set[T]) Add(value T) {
s.hashMap[value] = true
}
func (s *Set[T]) AddSlice(slice []T) {
for _, value := range slice {
s.Add(value)
func (s *Set[T]) Add(values ...T) {
for _, value := range values {
s.hashMap[value] = true
}
}