Skip to content

Instantly share code, notes, and snippets.

@catharinejm
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save catharinejm/8899708 to your computer and use it in GitHub Desktop.

Select an option

Save catharinejm/8899708 to your computer and use it in GitHub Desktop.
Defining a method on a function
package main
import (
"fmt"
)
type F func(x int) int
func (f F) doit (y int) int {
return f(y) + 3
}
func main() {
var f F = func(x int) int {
return 2 * x
}
fmt.Println(f(10))
fmt.Println(f.doit(10))
}
// Prints:
20
23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment