From c7a8aa113a914e70e027fea93265c7232b865b5e Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Fri, 7 Jun 2024 19:33:07 +0200 Subject: feat: Add compression --- pkg/u/list.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'pkg/u/list.go') diff --git a/pkg/u/list.go b/pkg/u/list.go index 34eafd1..cf71909 100644 --- a/pkg/u/list.go +++ b/pkg/u/list.go @@ -8,6 +8,14 @@ func First[T any](v []T) (T, bool) { return v[0], true } +func FirstOrZero[T any](v []T) T { + if len(v) == 0 { + var zero T + return zero + } + return v[0] +} + func ChunkBy[T any](items []T, chunkSize int) [][]T { var chunks = make([][]T, 0, (len(items)/chunkSize)+1) for chunkSize < len(items) { -- cgit v1.2.3