aboutsummaryrefslogtreecommitdiff
path: root/pkg/u/util.go
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2024-05-25 23:41:01 +0200
committerGabriel A. Giovanini <mail@gabrielgio.me>2024-05-25 23:41:40 +0200
commitc06945c189c1d8ef3cedeb51e416ba0fec36368f (patch)
treee9655b29715d5bae1d3fc5f669a74f2d7bde3c4e /pkg/u/util.go
parentce911df583e384d86018e42f9548cdf33d1c1549 (diff)
downloadcerrado-c06945c189c1d8ef3cedeb51e416ba0fec36368f.tar.gz
cerrado-c06945c189c1d8ef3cedeb51e416ba0fec36368f.tar.bz2
cerrado-c06945c189c1d8ef3cedeb51e416ba0fec36368f.zip
feat: Add utils
Diffstat (limited to 'pkg/u/util.go')
-rw-r--r--pkg/u/util.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/pkg/u/util.go b/pkg/u/util.go
new file mode 100644
index 0000000..34eafd1
--- /dev/null
+++ b/pkg/u/util.go
@@ -0,0 +1,17 @@
+package u
+
+func First[T any](v []T) (T, bool) {
+ if len(v) == 0 {
+ var zero T
+ return zero, false
+ }
+ return v[0], true
+}
+
+func ChunkBy[T any](items []T, chunkSize int) [][]T {
+ var chunks = make([][]T, 0, (len(items)/chunkSize)+1)
+ for chunkSize < len(items) {
+ items, chunks = items[chunkSize:], append(chunks, items[0:chunkSize:chunkSize])
+ }
+ return append(chunks, items)
+}