https://github.com/code-hex/yc
YC is the Y combinator in Go with generics
https://github.com/code-hex/yc
Last synced: 9 months ago
JSON representation
YC is the Y combinator in Go with generics
- Host: GitHub
- URL: https://github.com/code-hex/yc
- Owner: Code-Hex
- License: unlicense
- Created: 2022-06-13T01:41:41.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-06-13T10:57:16.000Z (over 3 years ago)
- Last Synced: 2025-02-05T14:42:16.990Z (10 months ago)
- Language: Go
- Size: 5.86 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# YC
YC is the Y combinator in Go with generics
This package is written based on the content of "[The Y combinator in Go with generics](https://eli.thegreenplace.net/2022/the-y-combinator-in-go-with-generics/)".
Implemented the Y combinator and some adaptions (e.g. memoize, tracing) for it.
## Synopsis
```go
package main
var factorialTag = func(recurse yc.Func[int, int]) yc.Func[int, int] {
return func(n int) int {
if n == 0 {
return 1
}
return n * recurse(n-1)
}
}
func main() {
fac := yc.Y(yc.Adapt(factorialTag, yc.Memo[int, int](), yc.Trace[int, int]()))
got := fac(10)
fmt.Println(got) // 3628800
}
```
## Run tests
```
$ go test -timeout 30s ./... github.com/Code-Hex/yc
```
## Run benchmark
```
$ go test -benchmem -bench . github.com/Code-Hex/yc
```