Skip to content

Instantly share code, notes, and snippets.

@pguillory
Created December 14, 2011 00:17
Show Gist options
  • Save pguillory/1474598 to your computer and use it in GitHub Desktop.
Save pguillory/1474598 to your computer and use it in GitHub Desktop.
package main
type SomeCollection struct {
members []int
}
func (this *SomeCollection) Append(i int) {
this.members = append(this.members, i)
}
func (this *SomeCollection) Each_callback(f func(int)) {
for _, member := range this.members {
f(member)
}
}
func (this *SomeCollection) Each_channel() chan int {
ch := make(chan int)
go func() {
for _, member := range this.members {
ch <- member
}
close(ch)
}()
return ch
}
func main() {
values := new(SomeCollection)
for i := 0; i < 1000000; i++ {
values.Append(i)
}
values.Each_callback(func(i int) {
i += 0
})
for i := range values.Each_channel() {
i += 0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment