summaryrefslogtreecommitdiff
path: root/vendor/github.com/samber/lo/mutable
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-07-15 16:37:08 -0600
committermo khan <mo@mokhan.ca>2025-07-17 16:30:22 -0600
commit45df4d0d9b577fecee798d672695fe24ff57fb1b (patch)
tree1b99bf645035b58e0d6db08c7a83521f41f7a75b /vendor/github.com/samber/lo/mutable
parentf94f79608393d4ab127db63cc41668445ef6b243 (diff)
feat: migrate from Cedar to SpiceDB authorization system
This is a major architectural change that replaces the Cedar policy-based authorization system with SpiceDB's relation-based authorization. Key changes: - Migrate from Rust to Go implementation - Replace Cedar policies with SpiceDB schema and relationships - Switch from envoy `ext_authz` with Cedar to SpiceDB permission checks - Update build system and dependencies for Go ecosystem - Maintain Envoy integration for external authorization This change enables more flexible permission modeling through SpiceDB's Google Zanzibar inspired relation-based system, supporting complex hierarchical permissions that were difficult to express in Cedar. Breaking change: Existing Cedar policies and Rust-based configuration will no longer work and need to be migrated to SpiceDB schema.
Diffstat (limited to 'vendor/github.com/samber/lo/mutable')
-rw-r--r--vendor/github.com/samber/lo/mutable/slice.go71
1 files changed, 71 insertions, 0 deletions
diff --git a/vendor/github.com/samber/lo/mutable/slice.go b/vendor/github.com/samber/lo/mutable/slice.go
new file mode 100644
index 00000000..969f3995
--- /dev/null
+++ b/vendor/github.com/samber/lo/mutable/slice.go
@@ -0,0 +1,71 @@
+package mutable
+
+import "github.com/samber/lo/internal/rand"
+
+// Filter is a generic function that modifies the input slice in-place to contain only the elements
+// that satisfy the provided predicate function. The predicate function takes an element of the slice and its index,
+// and should return true for elements that should be kept and false for elements that should be removed.
+// The function returns the modified slice, which may be shorter than the original if some elements were removed.
+// Note that the order of elements in the original slice is preserved in the output.
+func Filter[T any, Slice ~[]T](collection Slice, predicate func(item T) bool) Slice {
+ j := 0
+ for _, item := range collection {
+ if predicate(item) {
+ collection[j] = item
+ j++
+ }
+ }
+ return collection[:j]
+}
+
+// FilterI is a generic function that modifies the input slice in-place to contain only the elements
+// that satisfy the provided predicate function. The predicate function takes an element of the slice and its index,
+// and should return true for elements that should be kept and false for elements that should be removed.
+// The function returns the modified slice, which may be shorter than the original if some elements were removed.
+// Note that the order of elements in the original slice is preserved in the output.
+func FilterI[T any, Slice ~[]T](collection Slice, predicate func(item T, index int) bool) Slice {
+ j := 0
+ for i, item := range collection {
+ if predicate(item, i) {
+ collection[j] = item
+ j++
+ }
+ }
+ return collection[:j]
+}
+
+// Map is a generic function that modifies the input slice in-place to contain the result of applying the provided
+// function to each element of the slice. The function returns the modified slice, which has the same length as the original.
+func Map[T any, Slice ~[]T](collection Slice, fn func(item T) T) {
+ for i := range collection {
+ collection[i] = fn(collection[i])
+ }
+}
+
+// MapI is a generic function that modifies the input slice in-place to contain the result of applying the provided
+// function to each element of the slice. The function returns the modified slice, which has the same length as the original.
+func MapI[T any, Slice ~[]T](collection Slice, fn func(item T, index int) T) {
+ for i := range collection {
+ collection[i] = fn(collection[i], i)
+ }
+}
+
+// Shuffle returns an array of shuffled values. Uses the Fisher-Yates shuffle algorithm.
+// Play: https://go.dev/play/p/2xb3WdLjeSJ
+func Shuffle[T any, Slice ~[]T](collection Slice) {
+ rand.Shuffle(len(collection), func(i, j int) {
+ collection[i], collection[j] = collection[j], collection[i]
+ })
+}
+
+// Reverse reverses array so that the first element becomes the last, the second element becomes the second to last, and so on.
+// Play: https://go.dev/play/p/O-M5pmCRgzV
+func Reverse[T any, Slice ~[]T](collection Slice) {
+ length := len(collection)
+ half := length / 2
+
+ for i := 0; i < half; i = i + 1 {
+ j := length - 1 - i
+ collection[i], collection[j] = collection[j], collection[i]
+ }
+}