fn is a collection of go functional operators with generics
Go 1.18
go install golang.org/dl/go1.181@latest
go1.18 download
go get github.com/birwin93/fn
import "github.com/birwin93/fn"
func main() {
nums := []int{1, 2, 3}
sum := fn.Sum(nums)
filteredNums := fn.Filter(nums, func(i int) bool {
return i > 1
})
doubleNums := fn.Map(nums, func(i int) int {
return i * 2
})
if fn.Contains(nums, 2) {
fmt.Println("nums contains 2!")
}
}
See the open issues for a full list of proposed features (and known issues).
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/newfunction
) - Commit your Changes (
git commit -m 'Adds fn.NewFunction'
) - Push to the Branch (
git push origin feature/newfunction
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
Twitter - @billy_the_kid Project Link: https://github.com/birwin93/fn