mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-15 00:15:32 +02:00
would you believe that I'm adding even more generics
This commit is contained in:
22
vendor/github.com/jesseduffield/generics/slices/slices.go
generated
vendored
22
vendor/github.com/jesseduffield/generics/slices/slices.go
generated
vendored
@ -37,6 +37,16 @@ func Map[T any, V any](slice []T, f func(T) V) []V {
|
||||
return result
|
||||
}
|
||||
|
||||
// Produces a new slice, leaves the input slice untouched.
|
||||
func MapWithIndex[T any, V any](slice []T, f func(T, int) V) []V {
|
||||
result := make([]V, 0, len(slice))
|
||||
for i, value := range slice {
|
||||
result = append(result, f(value, i))
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// Produces a new slice, leaves the input slice untouched.
|
||||
func FlatMap[T any, V any](slice []T, f func(T) []V) []V {
|
||||
// impossible to know how long this slice will be in the end but the length
|
||||
@ -74,6 +84,18 @@ func Filter[T any](slice []T, test func(T) bool) []T {
|
||||
return result
|
||||
}
|
||||
|
||||
// Produces a new slice, leaves the input slice untouched.
|
||||
func FilterWithIndex[T any](slice []T, f func(T, int) bool) []T {
|
||||
result := make([]T, 0, len(slice))
|
||||
for i, value := range slice {
|
||||
if f(value, i) {
|
||||
result = append(result, value)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// Mutates original slice. Intended usage is to reassign the slice result to the input slice.
|
||||
func FilterInPlace[T any](slice []T, test func(T) bool) []T {
|
||||
newLength := 0
|
||||
|
Reference in New Issue
Block a user