summaryrefslogtreecommitdiffstats
path: root/vendor
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2022-03-19 19:51:48 +1100
committerJesse Duffield <jessedduffield@gmail.com>2022-03-24 20:14:41 +1100
commit94a53484a183bb32b066dc51fb90948dead634a1 (patch)
tree51e76a607b68a309c3e7573432392b125a3e2783 /vendor
parent1b75ed37403ac2997cb6a5ede92d87f1a1eb96b1 (diff)
would you believe that I'm adding even more generics
Diffstat (limited to 'vendor')
-rw-r--r--vendor/github.com/jesseduffield/generics/slices/slices.go22
-rw-r--r--vendor/modules.txt2
2 files changed, 23 insertions, 1 deletions
diff --git a/vendor/github.com/jesseduffield/generics/slices/slices.go b/vendor/github.com/jesseduffield/generics/slices/slices.go
index ec5653ddc..1d224255a 100644
--- a/vendor/github.com/jesseduffield/generics/slices/slices.go
+++ b/vendor/github.com/jesseduffield/generics/slices/slices.go
@@ -38,6 +38,16 @@ func Map[T any, V any](slice []T, f func(T) V) []V {
}
// 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
// of the original slice is the lower bound
@@ -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
diff --git a/vendor/modules.txt b/vendor/modules.txt
index 332871ffe..a7b196cea 100644
--- a/vendor/modules.txt
+++ b/vendor/modules.txt
@@ -120,7 +120,7 @@ github.com/integrii/flaggy
# github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99
## explicit
github.com/jbenet/go-context/io
-# github.com/jesseduffield/generics v0.0.0-20220319080325-a60171f800d5
+# github.com/jesseduffield/generics v0.0.0-20220319083513-5f145a9c0677
## explicit; go 1.18
github.com/jesseduffield/generics/maps
github.com/jesseduffield/generics/set