https://github.com/mickamy/gokitx
Utility helpers for Go 1.23+ that cover common patterns
https://github.com/mickamy/gokitx
Last synced: 5 months ago
JSON representation
Utility helpers for Go 1.23+ that cover common patterns
- Host: GitHub
- URL: https://github.com/mickamy/gokitx
- Owner: mickamy
- License: mit
- Created: 2025-10-17T13:06:15.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-10-18T02:02:10.000Z (8 months ago)
- Last Synced: 2025-10-19T01:29:23.504Z (8 months ago)
- Language: Go
- Size: 9.77 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gokitx
Utility helpers for Go 1.23+ that cover common patterns such as ternary evaluation, pointer helpers, and small tuple structs. The library is intentionally lightweight so you can drop in specific pieces without adopting a large framework.
## Modules
- `operator`: generic `Ternary` and `TernaryFunc` helpers that return eager or lazily computed values based on a boolean condition.
- `slices`: functional helpers like `Map`, `FlatMap`, `GroupBy`, `Find`, `Filter`, and `Unique` for working with collections.
- `ptr`: convenience functions for working with pointers, including `Of`, `Unwrap`, and `Map`.
- `tuple`: generic structs for 2–10 element tuples when you need to group multiple return values.
## Installation
```shell
go get github.com/mickamy/gokitx
```
## Usage
```go
package main
import (
"fmt"
"github.com/mickamy/gokitx/operator"
"github.com/mickamy/gokitx/ptr"
"github.com/mickamy/gokitx/slices"
"github.com/mickamy/gokitx/tuple"
)
func main() {
numbers := []int{1, 2, 2, 3}
unique := slices.Unique(numbers)
labels := slices.Map(unique, func(v int) string {
return fmt.Sprintf("value: %d", v)
})
selected, ok := slices.Find(unique, func(v int) bool {
return v > 1
})
n := operator.Ternary(ok, selected, 0)
p := ptr.Map(ptr.Of(n), func(v int) string {
return fmt.Sprintf("value: %d", v)
})
t := tuple.Triple[int, string, []string]{
First: n,
Second: ptr.Unwrap(p),
Third: labels,
}
fmt.Println(t)
}
```
## License
[MIT](./LICENSE)