Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lucperkins/fun
A functional programming library for generic Go
https://github.com/lucperkins/fun
Last synced: about 1 month ago
JSON representation
A functional programming library for generic Go
- Host: GitHub
- URL: https://github.com/lucperkins/fun
- Owner: lucperkins
- License: apache-2.0
- Created: 2022-02-06T06:42:23.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-02-06T18:11:08.000Z (almost 3 years ago)
- Last Synced: 2024-11-07T00:48:55.363Z (3 months ago)
- Language: Go
- Size: 14.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fun: a functional programming library for (generic) Go
A functional programming library for Go 1.18+. Currently mostly inspired by array functions in
JavaScript, but will likely grow over time.> Yes, there are many libraries out there like this. This is mostly a learning exercise for me.
## Current API
```go
// Any types
func ForEach[T any]([]T, func(T))
func Map[T any]([]T, func(T) T) []T
func Filter[T any]([]T, func(T) bool) []T
func Concat[T any]([]T, []T) []T
func Every[T any]([]T, func(T) bool) bool
func Any[T any]([]T, fn func(T) bool) bool
func Reduce[T any]([]T, fn func(T, T) T) T
func Reverse[T any]([]T) []T
func Pop[T any]([]T, int) (T, []T)
func Push[T any]([]T, T) []T// Comparable types
func Find[T comparable]([]T, func(T) bool) *T
func Includes[T comparable]([]T, T) bool
func Index[T comparable]([]T, T) int
func LastIndexOf[T comparable]([]T, T) int
func Replace[T comparable]([]T, T, T) []T
func ReplaceAll[T comparable]([]T, T, T) []T
func Delete[T comparable]([]T, T) []T
func DeleteAll[T comparable]([]T, T) []T// Ordered types
func Max[T Ordered]([]T) T
func Min[T Ordered]([]T) T
```