Given a Go source file, find the names of all functions that are known to be pure.
A "pure function" for this module is, a function that:
Example of a pure function:
func add(a, b int) int {
return a + b
}
Another example of a pure function (even though it is a "method"):
func (c *Config) Add(a, b int) int {
return a + b
}
go/ast
extensively.Pure functions, like the fibonacci
function, has great potential for optimization by memoization.
Benchmark output for "fibonacci" vs "memoized fibonacci":
goos: linux
goarch: amd64
pkg: github.com/xyproto/purefunction/example
BenchmarkFib10-8 30586 38894 ns/op
BenchmarkFibMemoized-8 84117813 14.2 ns/op
PASS
ok github.com/xyproto/purefunction/example 2.798s
See issue #1.