summaryrefslogtreecommitdiffstats
path: root/pkg/utils
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-05-27 14:14:43 +1000
committerJesse Duffield <jessedduffield@gmail.com>2023-07-03 12:54:13 +1000
commita9e2c8129f6e1cdfd58446d7ce5080fcabc2ea04 (patch)
tree272c6f737052d6e06f71c6e1e9ce355410238f1a /pkg/utils
parentfd861826bc11754caf4ee4651dbadf9544792d1f (diff)
Introduce filtered list view model
We're going to start supporting filtering of list views
Diffstat (limited to 'pkg/utils')
-rw-r--r--pkg/utils/slice.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/pkg/utils/slice.go b/pkg/utils/slice.go
index aff6ae470..4a47f43b1 100644
--- a/pkg/utils/slice.go
+++ b/pkg/utils/slice.go
@@ -113,3 +113,14 @@ func MoveElement[T any](slice []T, from int, to int) []T {
return newSlice
}
+
+func ValuesAtIndices[T any](slice []T, indices []int) []T {
+ result := make([]T, len(indices))
+ for i, index := range indices {
+ // gracefully handling the situation where the index is out of bounds
+ if index < len(slice) {
+ result[i] = slice[index]
+ }
+ }
+ return result
+}