Skip to content

Instantly share code, notes, and snippets.

@metakeule
Created January 24, 2013 16:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metakeule/4623836 to your computer and use it in GitHub Desktop.
Save metakeule/4623836 to your computer and use it in GitHub Desktop.
combine methods and functions that have the same primary argument, i.e. handle methods that are defined with the object and functions that are defined afterwards for this object (in another library) the same way.
package main
import "fmt"
type Foo struct{}
func (f *Foo) Method() {
fmt.Println("Method")
}
type Funcs []func(*Foo)
func Other(f *Foo) {
fmt.Println("Other")
}
func main() {
var fns = Funcs{}
fn := (*Foo).Method
fns = append(fns, fn)
fns = append(fns, Other)
var foo Foo
for _, ff := range fns {
ff(&foo)
}
//fn(&foo)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment