thunk
thunk
is a code generator to make interface's wrapper with methods evaluated lazily.
About
thunk
generates interface's wrapper for lazy evaluation.
Methods of the wrapper returns a thunk of the method call, instead of evaluating indivisually.
// original interface `Hello`
hello := NewHello()
hello.Greet("Tom")
// generated wrapper `LazyHello`
lazyHello := NewLazyHello(hello)
greetThunk := lazyHello.Greet("Bob") // Hello.Greet is not evaluated yet!
greetThunk() // Hello.Greet is evaluated here
See /_examples/hello for details.
Install
$ go install github.com/syuparn/thunk/cmd/thunk@latest
Usage
# generate wrapper code to zz_generated.thunk.go
$ thunk -o zz_generated.thunk.go example.com/your/package
Also, you can use go generate
to generate thunks.
//go:generate thunk -o zz_generated.thunk.go example.com/your/package
Note
This project uses skeleton to generate the module.