aboutsummaryrefslogtreecommitdiff
path: root/pkg/list
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/list')
-rw-r--r--pkg/list/list.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/pkg/list/list.go b/pkg/list/list.go
index dfc3fb7..3aa9d65 100644
--- a/pkg/list/list.go
+++ b/pkg/list/list.go
@@ -13,6 +13,25 @@ type Pair[T, U any] struct {
Right U
}
+func Chunck[T any](slice []T, size int) [][]T {
+ chuncks := make([][]T, size)
+
+ for i := 0; i < len(slice); i += size {
+ for x := 0; x < size; x++ {
+ end := i + x
+
+ if end > len(slice) {
+ break
+ }
+
+ chuncks[x] = append(chuncks[x], slice[end])
+ }
+
+ }
+
+ return chuncks
+}
+
func Zip[T, U any](left []T, right []U) []Pair[T, U] {
// pick the array with the smaller length
l := len(left)