From 99a7e9ab02ae1980874be35f6a2651ca4bfdb951 Mon Sep 17 00:00:00 2001 From: Gabriel Arakaki Giovanini Date: Fri, 6 Oct 2023 18:30:34 +0200 Subject: feat: Simplify mosaic The old implementation was not good and would render the list on mobile in the wrong order --- pkg/list/list.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'pkg/list/list.go') 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) -- cgit v1.2.3