Created
January 24, 2013 16:02
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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