Fp-go is a collection of Functional Programming helpers powered by Golang 1.18+ generics created by Repeale
This version was created as I needed more types for my projects, but most of the code (mainly on the slice functions) comes from the original version created by Repeale. Make sure to check it out.
Requires go 1.18+
go get github.com/force4760/fp-go
By default! Data last!
func isPositive(x int) bool {
return x > 0
}
func main() {
filterPositive := fp.Filter(isPositive)
numbers := []int{1, 2, 3, 4, 5}
positives := filterPositive(numbers)
}
Variations allows you to get different parameters in the callback function so that you get only only what is really needed.
Only the current item is available:
fp.Map[int, string](func(x int) { ... })
Current element and index are available:
fp.MapWithIndex[int, string](func(x int, i int) { ... })
Current element, index and the whole slice are available:
fp.MapWithSlice[int, string](func(x int, i int, xs: []int) { ... })
- Either
- Result
- Ranges