From d2a9e162352646e7f1550823c3d88496590f8760 Mon Sep 17 00:00:00 2001 From: Gabriel Arakaki Giovanini Date: Thu, 17 Aug 2023 21:38:27 +0200 Subject: ref: Update mosaic to remove empty spaces --- pkg/list/list.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'pkg/list/list.go') 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) -- cgit v1.2.3