Skip to content

quantumsheep/memo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Memo

memo is a Go library for memoization.

Installation

go get github.com/quantumsheep/memo

Example

This is an example of how to use memo to memoize the Fibonacci function.

func fib(n int) int {
    return memo.Memoize(func() int {
        if n < 2 {
            return n
            }

        return fib(n-1) + fib(n-2)
    }, n)
}

The first argument to memo.Memoize is a closure that returns a value. The next arguments are dependencies to be compared when determining whether to use the cached value or not.

About

Memoize Go functions on the fly

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages