Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jcouyang/fp.go
A light-weight FP utils lib for Go
https://github.com/jcouyang/fp.go
functional-programming go
Last synced: about 2 months ago
JSON representation
A light-weight FP utils lib for Go
- Host: GitHub
- URL: https://github.com/jcouyang/fp.go
- Owner: jcouyang
- License: bsd-3-clause
- Created: 2021-12-26T02:53:45.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-01-01T05:13:26.000Z (about 1 year ago)
- Last Synced: 2024-10-24T08:38:11.017Z (3 months ago)
- Topics: functional-programming, go
- Language: Go
- Homepage:
- Size: 433 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# FP Go
[![Go Reference](https://pkg.go.dev/badge/github.com/jcouyang/fp.go.svg)](https://pkg.go.dev/github.com/jcouyang/fp.go)
A light-weight FP utils for Go
## Usage
All functions are group by the data type they are processing, for
example we can `slices.Map` a function to a slice```go
import "github.com/jcouyang/fp.go/slices"strLen := func (a1 string) int {
return len(a1)
}fmt.Println(
slices.Map(strLen)([]string{"cat", "catfish", "caterpillar"}),
)
// Output: [3 7 11]
```Similarily, we can also `Map` the function to a `chan` with `chans.Map`
```go
import "github.com/jcouyang/fp.go/chans"wordChan := make(chan string, 3)
wordLenChan := chans.Map(strLen)(wordChan)wordChan <- "cat"
wordChan <- "catfish"
wordChan <- "caterpillar"
fmt.Println(
<-wordLenChan,
<-wordLenChan,
<-wordLenChan,
)
// Output: 3 7 11
```