mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-15 00:15:32 +02:00
refactor todo file generation
This commit is contained in:
26
vendor/github.com/jesseduffield/generics/slices/slices.go
generated
vendored
26
vendor/github.com/jesseduffield/generics/slices/slices.go
generated
vendored
@ -256,6 +256,7 @@ func Remove[T any](slice []T, index int) []T {
|
||||
return slices.Delete(slice, index, index+1)
|
||||
}
|
||||
|
||||
// Removes the element at the 'fromIndex' and then inserts it at 'toIndex'.
|
||||
// Operates on the input slice. Expected use is to reassign the result to the input slice.
|
||||
func Move[T any](slice []T, fromIndex int, toIndex int) []T {
|
||||
item := slice[fromIndex]
|
||||
@ -263,6 +264,12 @@ func Move[T any](slice []T, fromIndex int, toIndex int) []T {
|
||||
return slices.Insert(slice, toIndex, item)
|
||||
}
|
||||
|
||||
// Swaps two elements at the given indices.
|
||||
// Operates on the input slice.
|
||||
func Swap[T any](slice []T, index1 int, index2 int) {
|
||||
slice[index1], slice[index2] = slice[index2], slice[index1]
|
||||
}
|
||||
|
||||
// Similar to Append but we leave the original slice untouched and return a new slice
|
||||
func Concat[T any](slice []T, values ...T) []T {
|
||||
newSlice := make([]T, 0, len(slice)+len(values))
|
||||
@ -346,6 +353,17 @@ func Find[T any](slice []T, f func(T) bool) (T, bool) {
|
||||
return zero[T](), false
|
||||
}
|
||||
|
||||
// Sometimes you need to find an element and then map it to some other value based on
|
||||
// information you obtained while finding it. This function lets you do that
|
||||
func FindMap[T any, V any](slice []T, f func(T) (V, bool)) (V, bool) {
|
||||
for _, element := range slice {
|
||||
if value, ok := f(element); ok {
|
||||
return value, true
|
||||
}
|
||||
}
|
||||
return zero[V](), false
|
||||
}
|
||||
|
||||
func ForEach[T any](slice []T, f func(T)) {
|
||||
for _, element := range slice {
|
||||
f(element)
|
||||
@ -376,6 +394,14 @@ func TryForEachWithIndex[T any](slice []T, f func(T, int) error) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func Sum[T constraints.Ordered](i []T) T {
|
||||
sum := zero[T]()
|
||||
for _, value := range i {
|
||||
sum += value
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
func zero[T any]() T {
|
||||
var value T
|
||||
return value
|
||||
|
Reference in New Issue
Block a user