Created
December 14, 2011 00:17
-
-
Save pguillory/1474598 to your computer and use it in GitHub Desktop.
This file contains 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 | |
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