aboutsummaryrefslogtreecommitdiff
path: root/pkg/u/list.go
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2024-05-26 20:33:37 +0200
committerGabriel A. Giovanini <mail@gabrielgio.me>2024-05-26 20:33:37 +0200
commit4534dffb865eb1a50bfbc291a5c3798183081caf (patch)
treed5bd1a2d9912a6442e3be1511ffb1d99f12287b0 /pkg/u/list.go
parent349a3d1ff36a436261b1b65b870f8f262f06584f (diff)
downloadcerrado-4534dffb865eb1a50bfbc291a5c3798183081caf.tar.gz
cerrado-4534dffb865eb1a50bfbc291a5c3798183081caf.tar.bz2
cerrado-4534dffb865eb1a50bfbc291a5c3798183081caf.zip
feat: Add actual git listing implementation
Diffstat (limited to 'pkg/u/list.go')
-rw-r--r--pkg/u/list.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/pkg/u/list.go b/pkg/u/list.go
new file mode 100644
index 0000000..34eafd1
--- /dev/null
+++ b/pkg/u/list.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)
+}