aboutsummaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
Diffstat (limited to 'pkg')
-rw-r--r--pkg/list/list.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/pkg/list/list.go b/pkg/list/list.go
index 482e5bf..8f3d875 100644
--- a/pkg/list/list.go
+++ b/pkg/list/list.go
@@ -31,6 +31,24 @@ func Distribuite[T any](slice []T, size int) [][]T {
return chuncks
}
+func Chunck[T any](slice []T, size int) [][]T {
+ var divided [][]T
+
+ chunkSize := (len(slice) + size - 1) / size
+
+ for i := 0; i < len(slice); i += chunkSize {
+ end := i + chunkSize
+
+ if end > len(slice) {
+ end = len(slice)
+ }
+
+ divided = append(divided, slice[i:end])
+ }
+
+ return divided
+}
+
func Zip[T, U any](left []T, right []U) []Pair[T, U] {
// pick the array with the smaller length
l := len(left)