Skip to content

Code-Hex/yc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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".

Implemented the Y combinator and some adaptions (e.g. memoize, tracing) for it.

Synopsis

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

About

YC is the Y combinator in Go with generics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages