aboutsummaryrefslogtreecommitdiff
path: root/pkg/list
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/list')
-rw-r--r--pkg/list/list.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/pkg/list/list.go b/pkg/list/list.go
index ff259f7..dfc3fb7 100644
--- a/pkg/list/list.go
+++ b/pkg/list/list.go
@@ -7,3 +7,28 @@ func Map[V any, T any](source []V, fun func(V) T) []T {
}
return result
}
+
+type Pair[T, U any] struct {
+ Left T
+ Right U
+}
+
+func Zip[T, U any](left []T, right []U) []Pair[T, U] {
+ // pick the array with the smaller length
+ l := len(left)
+ if len(left) > len(right) {
+ l = len(right)
+ }
+
+ pairs := make([]Pair[T, U], len(left))
+ for i := 0; i < l; i++ {
+ pairs[i] = Pair[T, U]{left[i], right[i]}
+ }
+ return pairs
+}
+
+func Revert[T any](s []T) {
+ for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
+ s[i], s[j] = s[j], s[i]
+ }
+}