1
0
Fork 0
mirror of https://github.com/vbatts/talks.git synced 2024-12-28 01:26:33 +00:00
talks/2015/02-devconf.cz/primitive3.go

38 lines
533 B
Go
Raw Normal View History

2015-02-05 23:58:25 +00:00
// +build ignore
package main
import "fmt"
func main() {
// START1 OMIT
fmt.Println("I've got:")
for card := range ReadEmAndWeep() {
fmt.Printf(" %s of %s\n", card.Value, card.Suite)
}
// STOP1 OMIT
}
type Card struct {
Suite, Value string
}
// START2 OMIT
func ReadEmAndWeep() <-chan Card {
c := make(chan Card)
go func() {
for _, card := range []Card{
Card{"Ace", "Jack"},
Card{"Ace", "Queen"},
Card{"Ace", "King"},
Card{"Ace", "Ace"},
} {
c <- card
}
close(c)
}()
return c
}
// STOP2 OMIT