All generic functions for Go you ever need!
Generic functions for Go. Bringing the beauty of functional programming in Go 1.18+.
ð Features:
ðĻ When to use:
slices.Shrink
is a function with a human-friendly name and documentation. s[:len(s):len(s)]
is a jibberish and black magic. Prefer the former.ðĶ What's inside:
Filter
, Map
, and Reduce
for data processing on steroids.FilterAsync
, MapAsync
, and ReduceAsync
for making your code fast and concurrent with a single line of code.Grow
and Shrink
for reducing memory allocations.Permutations
and Product
for simple iterations.Shuffle
and Sort
for randomization.Any
and All
for simple flow control.Range
, Count
, and Cycle
for generating sequences.And much more.
go get github.com/life4/genesis
Find the minimal value in a slice of ints:
lambdas.Must(slices.Min([]int{42, 7, 13})) == 7
Double values in a slice of ints:
slices.Map([]int{4, 8, 15}, func(el int) int { return el * 2 })
Concurrently check status codes for multiple URLs:
urls := []string{
"https://go.dev/",
"https://golang.org/",
"https://google.com/",
}
codes := slices.MapAsync(
urls, 0,
func(url string) int {
return lambdas.Must(http.Get(url)).StatusCode
},
)
Genesis contains the following packages:
[]T
).map[K]V
).chan T
).map[T]struct{}
).slices.Map
and similar.See ð DOCUMENTATION for more info.