aboutsummaryrefslogtreecommitdiff
path: root/pkg/list
diff options
context:
space:
mode:
authorGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-10-06 18:30:34 +0200
committerGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-10-06 18:41:13 +0200
commit99a7e9ab02ae1980874be35f6a2651ca4bfdb951 (patch)
tree71d4a3f2a7e7df2b527344158dc8b7c684fef518 /pkg/list
parent91f7c40479aa9ef18c7927913be49a014a8a3115 (diff)
downloadlens-99a7e9ab02ae1980874be35f6a2651ca4bfdb951.tar.gz
lens-99a7e9ab02ae1980874be35f6a2651ca4bfdb951.tar.bz2
lens-99a7e9ab02ae1980874be35f6a2651ca4bfdb951.zip
feat: Simplify mosaic
The old implementation was not good and would render the list on mobile in the wrong order
Diffstat (limited to 'pkg/list')
-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)