Skip to content

Instantly share code, notes, and snippets.

@pallat
Last active February 18, 2016 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pallat/ddb16ee92c33b24a8283 to your computer and use it in GitHub Desktop.
Save pallat/ddb16ee92c33b24a8283 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
type slice []int
type loopFn func(int)
func (a *slice) forEach(fn loopFn) {
for _, e := range *a {
fn(e)
}
}
func main() {
a := slice{
1, 2, 3, 4, 5, 6, 7, 8, 9,
}
a.forEach(func(i int) {
fmt.Println(i)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment