A collection of utility packages for Go, providing ergonomic and type-safe helpers for common operations on slices and maps.
Utilities for working with slices, including functional programming patterns and advanced collection operations.
Key Features:
Collect: Advanced iteration with immediate control flow (Stop/Continue) and rich error handlingFilter,Map,Reduce: Standard functional operationsEvery,Some,Find,Contains: Predicate-based queriesSliceError: Detailed error tracking with element context (index, value)
Example:
import "github.com/cirius-go/devutil/slice"
result, err := slice.Collect(input, func(c slice.CollectorContext[int, int]) {
_, val := c.CurrentElem()
if shouldSkip(val) {
c.Continue() // Skip immediately
}
if isFatal(val) {
c.Stop(err) // Stop immediately with error
}
c.SetValue(val * 2)
})Utilities for working with maps (records/associative arrays), providing common transformation and access patterns.
Key Features:
Keys,Values: Extract to slicesSortedKeys,SortedValues: Ordered extractionClone,Merge: Map operationsFilter,MapValues: TransformationsToSet: Convert slice to setAssociate: Build map from slice with transform
Example:
import "github.com/cirius-go/devutil/record"
// Create a set from slice
set := record.ToSet([]string{"a", "b", "a"})
// map[string]struct{}{"a":{}, "b":{}}
// Transform slice to map
lengths := record.Associate(words, func(w string) (string, int) {
return w, len(w)
})go get github.com/cirius-go/devutil- Go 1.21+ (uses generics and standard library features like
cmp.Ordered)
- slice.Collect: ~5x slower than native loops due to abstraction overhead. Best for business logic where ergonomics matter.
- Utility functions: Rank 1 performance (native loop speed). Use for simple operations.
[Add your license here]