SlideShare a Scribd company logo
going loopy
adventures in iteration with google go
@feyeleanor
Going Loopy http://slideshare.net/feyeleanor/1
the task
Going Loopy http://slides.games-with-brains.net/2
0: 0
1: 2
2: 4
3: 6
4: 8
Going Loopy http://slides.games-with-brains.net/3
the conditional loop
Going Loopy http://slides.games-with-brains.net/4
package main
import "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
for i := 0; i < len(s); i++ {
fmt.Printf("%v: %vn", i, s[i])
}
}
Going Loopy http://slides.games-with-brains.net/5
package main
import "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
for i := 0; i < len(s); i++ {
fmt.Printf("%v: %vn", i, s[i])
}
}
Going Loopy http://slides.games-with-brains.net/6
package main
import . "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
for i := 0; i < len(s); i++ {
Printf("%v: %vn", i, s[i])
}
}
7Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
for i := 0; i < len(s); i++ {
Printf("%v: %vn", i, s[i])
}
}
8Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
for i := 0; i < len(s); i++ {
Printf("%v: %vn", i, s[i])
}
}
9Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
for i := 0; i < len(s); i++ {
Printf("%v: %vn", i, s[i])
}
}
Going Loopy http://slides.games-with-brains.net/10
package main
import . "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
for i := 0; i < len(s); i++ {
Printf("%v: %vn", i, s[i])
}
}
Going Loopy http://slides.games-with-brains.net/11
package main
import . "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
for i := 0; i < len(s); i++ {
Printf("%v: %vn", i, s[i])
}
}
Going Loopy http://slides.games-with-brains.net/12
package main
import . "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
for i := 0; i < len(s); i++ {
Printf("%v: %vn", i, s[i])
}
}
Going Loopy http://slides.games-with-brains.net/13
package main
import . "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
for i := 0; i < len(s); i++ {
Printf("%v: %vn", i, s[i])
}
}
Going Loopy http://slides.games-with-brains.net/14
package main
import . "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
for i := 0; i < len(s); i++ {
Printf("%v: %vn", i, s[i])
}
}
Going Loopy http://slides.games-with-brains.net/15
package main
import . "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
for i := 0; i < len(s); i++ {
Printf("%v: %vn", i, s[i])
}
}
Going Loopy http://slides.games-with-brains.net/16
package main
import . "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
for i := 0; i < len(s); i++ {
Printf("%v: %vn", i, s[i])
}
}
17Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
for i := 0; i < len(s); i++ {
Printf("%v: %vn", i, s[i])
}
}
Going Loopy http://slides.games-with-brains.net/18
package main
import . "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
for i := 0; i < len(s); i++ {
Printf("%v: %vn", i, s[i])
}
}
Going Loopy http://slides.games-with-brains.net/19
package main
import . "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
for i := 0; i < len(s); i++ {
Printf("%v: %vn", i, s[i])
}
}
Going Loopy http://slides.games-with-brains.net/20
package main
import . "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
for i := 0; i < len(s); i++ {
Printf("%v: %vn", i, s[i])
}
}
Going Loopy http://slides.games-with-brains.net/21
the infinite loop
Going Loopy http://slides.games-with-brains.net/22
package main
import . "fmt"
func main() {
defer func() {
recover()
}()
s := []int{0, 2, 4, 6, 8}
i := 0
for {
Printf("%v: %vn", i, s[i])
i++
}
}
Going Loopy http://slides.games-with-brains.net/23
package main
import . "fmt"
func main() {
defer func() {
recover()
}()
s := []int{0, 2, 4, 6, 8}
i := 0
for {
Printf("%v: %vn", i, s[i])
i++
}
}
Going Loopy http://slides.games-with-brains.net/24
package main
import . "fmt"
func main() {
defer func() {
recover()
}()
s := []int{0, 2, 4, 6, 8}
i := 0
for {
Printf("%v: %vn", i, s[i])
i++
}
}
Going Loopy http://slides.games-with-brains.net/25
package main
import . "fmt"
func main() {
defer func() {
recover()
}()
s := []int{0, 2, 4, 6, 8}
i := 0
for {
Printf("%v: %vn", i, s[i])
i++
}
}
Going Loopy http://slides.games-with-brains.net/26
package main
import . "fmt"
func main() {
defer func() {
recover()
}()
s := []int{0, 2, 4, 6, 8}
i := 0
for {
Printf("%v: %vn", i, s[i])
i++
}
}
Going Loopy http://slides.games-with-brains.net/27
package main
import . "fmt"
func main() {
defer func() {
recover()
}()
s := []int{0, 2, 4, 6, 8}
i := 0
for i := 0; ; i++ {
Printf("%v: %vn", i, s[i])
i++
}
}
Going Loopy http://slides.games-with-brains.net/28
the range
Going Loopy http://slides.games-with-brains.net/29
package main
import . "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
for i, v := range s {
Printf("%v: %vn", i, v)
}
}
Going Loopy http://slides.games-with-brains.net/30
package main
import . "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
for i, v := range s {
Printf("%v: %vn", i, v)
}
}
Going Loopy http://slides.games-with-brains.net/31
package main
import . "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
for i, v := range s {
Printf("%v: %vn", i, v)
}
}
Going Loopy http://slides.games-with-brains.net/32
package main
import . "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
for i, v := range s {
Printf("%v: %vn", i, v)
}
}
Going Loopy http://slides.games-with-brains.net/33
package main
import . "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
for i, v := range s {
Printf("%v: %vn", i, v)
}
}
Going Loopy http://slides.games-with-brains.net/34
a functional interlude
35Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
func main() {
print_slice([]int{0, 2, 4, 6, 8})
}
func print_slice(s []int) {
for i, v := range s {
Printf("%v: %vn", i, v)
}
}
36Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
func main() {
print_slice([]int{0, 2, 4, 6, 8})
}
func print_slice(s []int) {
for i, v := range s {
Printf("%v: %vn", i, v)
}
}
37Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
func main() {
print_slice([]int{0, 2, 4, 6, 8})
}
func print_slice(s []int) {
for i, v := range s {
Printf("%v: %vn", i, v)
}
}
38Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
func main() {
print_slice(0, 2, 4, 6, 8)
}
func print_slice(s ...int) {
for i, v := range s {
Printf("%v: %vn", i, v)
}
}
39Going Loopy http://slides.games-with-brains.net/
asserting type
Going Loopy http://slides.games-with-brains.net/40
package main
import . "fmt"
func main() {
print_slice([]int{0, 2, 4, 6, 8})
}
func print_slice(s interface{}) {
for i, v := range s.([]int) {
Printf("%v: %vn", i, v)
}
}
Going Loopy http://slides.games-with-brains.net/41
package main
import . "fmt"
func main() {
print_slice([]int{0, 2, 4, 6, 8})
}
func print_slice(s interface{}) {
for i, v := range s.([]int) {
Printf("%v: %vn", i, v)
}
}
Going Loopy http://slides.games-with-brains.net/42
package main
import . "fmt"
func main() {
print_slice([]int{0, 2, 4, 6, 8})
}
func print_slice(s interface{}) {
if s, ok := s.([]int); ok {
for i, v := range s {
Printf("%v: %vn", i, v)
}
}
}
Going Loopy http://slides.games-with-brains.net/43
package main
import . "fmt"
func main() {
print_slice([]int{0, 2, 4, 6, 8})
}
func print_slice(s interface{}) {
if s, ok := s.([]int); ok {
for i, v := range s {
Printf("%v: %vn", i, v)
}
}
}
Going Loopy http://slides.games-with-brains.net/44
package main
import . "fmt"
func main() {
print_slice([]int{0, 2, 4, 6, 8})
}
func print_slice(s interface{}) {
if s, ok := s.([]int); ok {
for i, v := range s {
Printf("%v: %vn", i, v)
}
}
}
Going Loopy http://slides.games-with-brains.net/45
package main
import . "fmt"
func main() {
print_slice([]int{0, 2, 4, 6, 8})
}
func print_slice(s interface{}) {
if s, ok := s.([]int); ok {
for i, v := range s {
Printf("%v: %vn", i, v)
}
}
}
Going Loopy http://slides.games-with-brains.net/46
package main
import . "fmt"
func main() {
print_slice([]int{0, 2, 4, 6, 8})
}
func print_slice(s interface{}) {
switch s := s.(type) {
case []int:
for i, v := range s {
Printf("%v: %vn", i, v)
}
}
}
Going Loopy http://slides.games-with-brains.net/47
package main
import . "fmt"
func main() {
print_slice([]int{0, 2, 4, 6, 8})
}
func print_slice(s interface{}) {
switch s := s.(type) {
case []int:
for i, v := range s {
Printf("%v: %vn", i, v)
}
}
}
Going Loopy http://slides.games-with-brains.net/48
package main
import . "fmt"
func main() {
print_slice([]int{0, 2, 4, 6, 8})
}
func print_slice(s interface{}) {
switch s := s.(type) {
case []int:
for i, v := range s {
Printf("%v: %vn", i, v)
}
}
}
Going Loopy http://slides.games-with-brains.net/49
closures
50Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
print_slice(func(i int) int { return s[i] })
}
func print_slice(s interface{}) {
switch s := s.(type) {
case func(int) int:
for i := 0; i < 5; i++ {
Printf("%v: %vn", i, s(i))
}
}
}
51Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
print_slice(func(i int) int { return s[i] })
}
func print_slice(s interface{}) {
switch s := s.(type) {
case func(int) int:
for i := 0; i < 5; i++ {
Printf("%v: %vn", i, s(i))
}
}
}
52Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
print_slice(func(i int) int { return s[i] })
}
func print_slice(s interface{}) {
switch s := s.(type) {
case func(int) int:
for i := 0; i < 5; i++ {
Printf("%v: %vn", i, s(i))
}
}
}
53Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
print_slice(func(i int) int { return s[i] })
}
func print_slice(s interface{}) {
switch s := s.(type) {
case func(int) int:
for i := 0; i < 5; i++ {
Printf("%v: %vn", i, s(i))
}
}
}
54Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
print_slice(func(i int) int { return s[i] })
}
func print_slice(s interface{}) {
switch s := s.(type) {
case func(int) int:
for i := 0; i < 5; i++ {
Printf("%v: %vn", i, s(i))
}
}
}
55Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
print_slice(func(i int) int { return s[i] })
}
func print_slice(s interface{}) {
switch s := s.(type) {
case func(int) int:
for i := 0; i < 5; i++ {
Printf("%v: %vn", i, s(i))
}
}
}
56Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
print_slice(func(i int) int { return s[i] })
}
func print_slice(s interface{}) {
switch s := s.(type) {
case func(int) int:
for i := 0; i < 5; i++ {
Printf("%v: %vn", i, s(i))
}
}
}
57Going Loopy http://slides.games-with-brains.net/
channels
58Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
func main() {
c := make(chan int)
go func() {
for _, v := range []int{0, 2, 4, 6, 8} {
c <- v
}
close(c)
}()
Printf("elements: %vn", print_channel(c))
}
func print_channel(c chan int) (i int) {
for v := range c {
Printf("%v: %vn", i, v)
i++
}
return
}
59Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
func main() {
c := make(chan int, 16)
go func() {
for _, v := range []int{0, 2, 4, 6, 8} {
c <- v
}
close(c)
}()
Printf("elements: %vn", print_channel(c))
}
func print_channel(c chan int) (i int) {
for v := range c {
Printf("%v: %vn", i, v)
i++
}
return
}
60Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
func main() {
c := make(chan int)
go func() {
for _, v := range []int{0, 2, 4, 6, 8} {
c <- v
}
close(c)
}()
Printf("elements: %vn", print_channel(c))
}
func print_channel(c chan int) (i int) {
for v := range c {
Printf("%v: %vn", i, v)
i++
}
return
}
61Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
func main() {
c := make(chan int)
go func() {
for _, v := range []int{0, 2, 4, 6, 8} {
c <- v
}
close(c)
}()
Printf("elements: %vn", print_channel(c))
}
func print_channel(c chan int) (i int) {
for v := range c {
Printf("%v: %vn", i, v)
i++
}
return
}
62Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
func main() {
c := make(chan int)
go func() {
for _, v := range []int{0, 2, 4, 6, 8} {
c <- v
}
close(c)
}()
Printf("elements: %vn", print_channel(c))
}
func print_channel(c chan int) (i int) {
for v := range c {
Printf("%v: %vn", i, v)
i++
}
return
}
63Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
func main() {
c := make(chan int)
go func() {
for _, v := range []int{0, 2, 4, 6, 8} {
c <- v
}
close(c)
}()
Printf("elements: %vn", print_channel(c))
}
func print_channel(c chan int) (i int) {
for v := range c {
Printf("%v: %vn", i, v)
i++
}
return
}
64Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
func main() {
c := make(chan int)
go func() {
for _, v := range []int{0, 2, 4, 6, 8} {
c <- v
}
close(c)
}()
Printf("elements: %vn", print_channel(c))
}
func print_channel(c chan int) (i int) {
for v := range c {
Printf("%v: %vn", i, v)
i++
}
return
}
65Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
func main() {
c := make(chan int)
go func() {
for _, v := range []int{0, 2, 4, 6, 8} {
c <- v
}
close(c)
}()
Printf("elements: %vn", print_channel(c))
}
func print_channel(c chan int) (i int) {
for v := range c {
Printf("%v: %vn", i, v)
i++
}
return
}
66Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
func main() {
c := make(chan int)
go func() {
for _, v := range []int{0, 2, 4, 6, 8} {
c <- v
}
close(c)
}()
Printf("elements: %vn", print_channel(c))
}
func print_channel(c chan int) (i int) {
for v := range c {
Printf("%v: %vn", i, v)
i++
}
return
}
67Going Loopy http://slides.games-with-brains.net/
upon reflection
68Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
print_values(s)
print_values(func(i int) int { return s[i] })
}
func print_values(s interface{}) {
switch s := s.(type) {
case func(int) int:
for i := 0; i < 5; i++ {
Printf("%v: %vn", i, s(i))
}
case []int:
for i, v := range s {
Printf("%v: %vn", i, v)
}
}
}
69Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
print_values(s)
print_values(func(i int) int { return s[i] })
}
func print_values(s interface{}) {
switch s := s.(type) {
case func(int) int:
for i := 0; i < 5; i++ {
Printf("%v: %vn", i, s(i))
}
case []int:
for i, v := range s {
Printf("%v: %vn", i, v)
}
}
}
70Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
func main() {
s := []int{0, 2, 4, 6, 8}
print_values(s)
print_values(func(i int) int { return s[i] })
}
func print_values(s interface{}) {
switch s := s.(type) {
case func(int) int:
for i := 0; i < 5; i++ {
Printf("%v: %vn", i, s(i))
}
case []int:
for i, v := range s {
Printf("%v: %vn", i, v)
}
}
}
71Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
import "reflect"
func main() {
s := []int{0, 2, 4, 6, 8}
print_values(s)
print_values(func(i int) int { return s[i] })
}
func print_values(s interface{}) {
switch s := reflect.ValueOf(s); s.Kind() {
case reflect.Func:
for i := 0; i < 5; i++ {
p := []reflect.Value{ reflect.ValueOf(i) }
Printf("%v: %vn", i, s.Call(p)[0].Interface{})
}
case reflect.Slice:
for i := 0; i < s.Len(); i++ {
Printf("%v: %vn", i, s.Index(i))
}
}
}
72Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
import "reflect"
func main() {
s := []int{0, 2, 4, 6, 8}
print_values(s)
print_values(func(i int) int { return s[i] })
}
func print_values(s interface{}) {
switch s := reflect.ValueOf(s); s.Kind() {
case reflect.Func:
for i := 0; i < 5; i++ {
p := []reflect.Value{ reflect.ValueOf(i) }
Printf("%v: %vn", i, s.Call(p)[0].Interface())
}
case reflect.Slice:
for i := 0; i < s.Len(); i++ {
Printf("%v: %vn", i, s.Index(i).Interface())
}
}
}
73Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
import "reflect"
func main() {
s := []int{0, 2, 4, 6, 8}
print_values(s)
print_values(func(i int) int { return s[i] })
}
func print_values(s interface{}) {
switch s := reflect.ValueOf(s); s.Kind() {
case reflect.Func:
for i := 0; i < 5; i++ {
p := []reflect.Value{ reflect.ValueOf(i) }
Printf("%v: %vn", i, s.Call(p)[0].Interface())
}
case reflect.Slice:
for i := 0; i < s.Len(); i++ {
Printf("%v: %vn", i, s.Index(i).Interface())
}
}
}
74Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
import "reflect"
func main() {
s := []int{0, 2, 4, 6, 8}
print_values(s)
print_values(func(i int) int { return s[i] })
}
func print_values(s interface{}) {
switch s := reflect.ValueOf(s); s.Kind() {
case reflect.Func:
for i := 0; i < 5; i++ {
p := []reflect.Value{ reflect.ValueOf(i) }
Printf("%v: %vn", i, s.Call(p)[0].Interface())
}
case reflect.Slice:
for i := 0; i < s.Len(); i++ {
Printf("%v: %vn", i, s.Index(i).Interface())
}
}
}
75Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
import "reflect"
func main() {
s := []int{0, 2, 4, 6, 8}
print_values(s)
print_values(func(i int) int { return s[i] })
}
func print_values(s interface{}) {
switch s := reflect.ValueOf(s); s.Kind() {
case reflect.Func:
for i := 0; i < 5; i++ {
p := []reflect.Value{ reflect.ValueOf(i) }
Printf("%v: %vn", i, s.Call(p)[0].Interface())
}
case reflect.Slice:
for i := 0; i < s.Len(); i++ {
Printf("%v: %vn", i, s.Index(i).Interface())
}
}
}
76Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
import . "reflect"
func main() {
s := []int{0, 2, 4, 6, 8}
print_values(s)
print_values(func(i int) int { return s[i] })
}
func print_values(s interface{}) {
switch s := ValueOf(s); s.Kind() {
case Func:
for i := 0; i < 5; i++ {
p := []Value{ ValueOf(i) }
Printf("%v: %vn", i, s.Call(p)[0].Interface())
}
case Slice:
for i := 0; i < s.Len(); i++ {
Printf("%v: %vn", i, s.Index(i).Interface())
}
}
}
77Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
import . "reflect"
func main() {
s := []int{0, 2, 4, 6, 8}
print_values(s)
print_values(func(i int) int { return s[i] })
}
func print_values(s interface{}) {
switch s := ValueOf(s); s.Kind() {
case Func:
for i := 0; i < 5; i++ {
p := []Value{ ValueOf(i) }
Printf("%v: %vn", i, s.Call(p)[0].Interface())
}
case Slice:
for i := 0; i < s.Len(); i++ {
Printf("%v: %vn", i, s.Index(i).Interface())
}
}
}
78Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
import . "reflect"
func main() {
s := []int{0, 2, 4, 6, 8}
print_values(s)
print_values(func(i int) int { return s[i] })
}
func print_values(s interface{}) {
switch s := ValueOf(s); s.Kind() {
case Func:
for i := 0; i < 5; i++ {
p := []Value{ ValueOf(i) }
Printf("%v: %vn", i, s.Call(p)[0].Interface())
}
case Slice:
for i := 0; i < s.Len(); i++ {
Printf("%v: %vn", i, s.Index(i).Interface())
}
}
}
79Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
import . "reflect"
func main() {
s := []int{0, 2, 4, 6, 8}
print_values(s)
print_values(func(i int) int { return s[i] })
}
func print_values(s interface{}) {
switch s := ValueOf(s); s.Kind() {
case Func:
for i := 0; i < 5; i++ {
p := []Value{ ValueOf(i) }
Printf("%v: %vn", i, s.Call(p)[0].Interface())
}
case Slice:
for i := 0; i < s.Len(); i++ {
Printf("%v: %vn", i, s.Index(i).Interface())
}
}
}
80Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
import . "reflect"
func main() {
s := []int{0, 2, 4, 6, 8}
print_values(s)
print_values(func(i int) int { return s[i] })
}
func print_values(s interface{}) {
switch s := ValueOf(s); s.Kind() {
case Func:
for i := 0; i < 5; i++ {
p := []Value{ ValueOf(i) }
Printf("%v: %vn", i, s.Call(p)[0].Interface())
}
case Slice:
for i := 0; i < s.Len(); i++ {
Printf("%v: %vn", i, s.Index(i).Interface())
}
}
}
81Going Loopy http://slides.games-with-brains.net/
user-defined type
82Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
type IterableSlice []int
func (i IterableSlice) Each(f func(interface{})) {
for _, v := range i {
f(v)
}
}
func main() {
s := IterableSlice{ 0, 2, 4, 6, 8 }
i := 0
s.Each(func(v interface{}) {
Printf("%v: %vn", i, v)
i++
})
}
83Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
type IterableSlice []int
func (i IterableSlice) Each(f func(interface{})) {
for _, v := range i {
f(v)
}
}
func main() {
s := IterableSlice{ 0, 2, 4, 6, 8 }
i := 0
s.Each(func(v interface{}) {
Printf("%v: %vn", i, v)
i++
})
}
84Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
type IterableSlice []int
func (i IterableSlice) Each(f func(interface{})) {
for _, v := range i {
f(v)
}
}
func main() {
s := IterableSlice{ 0, 2, 4, 6, 8 }
i := 0
s.Each(func(v interface{}) {
Printf("%v: %vn", i, v)
i++
})
}
85Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
type IterableSlice []int
func (i IterableSlice) Each(f func(interface{})) {
for _, v := range i {
f(v)
}
}
func main() {
s := IterableSlice{ 0, 2, 4, 6, 8 }
i := 0
s.Each(func(v interface{}) {
Printf("%v: %vn", i, v)
i++
})
}
86Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
type IterableSlice []int
func (i IterableSlice) Each(f func(interface{})) {
for _, v := range i {
f(v)
}
}
func main() {
s := IterableSlice{ 0, 2, 4, 6, 8 }
i := 0
s.Each(func(v interface{}) {
Printf("%v: %vn", i, v)
i++
})
}
87Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
type IterableSlice []int
func (i IterableSlice) Each(f func(interface{})) {
for _, v := range i {
f(v)
}
}
func main() {
s := IterableSlice{ 0, 2, 4, 6, 8 }
i := 0
s.Each(func(v interface{}) {
Printf("%v: %vn", i, v)
i++
})
}
88Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
type IterableSlice []int
func (i IterableSlice) Each(f func(interface{})) {
for _, v := range i {
f(v)
}
}
func main() {
s := IterableSlice{ 0, 2, 4, 6, 8 }
i := 0
s.Each(func(v interface{}) {
Printf("%v: %vn", i, v)
i++
})
}
89Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
type Iterable interface {
Each(func(interface{}))
}
type IterableSlice []int
func (i IterableSlice) Each(f func(interface{})) {
for _, v := range i {
f(v)
}
}
func main() {
var s Iterable = IterableSlice{ 0, 2, 4, 6, 8 }
i := 0
s.Each(func(v interface{}) {
Printf("%v: %vn", i, v)
i++
})
}
90Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
type Iterable interface {
Each(func(interface{}))
}
type IterableSlice []int
func (i IterableSlice) Each(f func(interface{})) {
for _, v := range i {
f(v)
}
}
func main() {
var s Iterable = IterableSlice{ 0, 2, 4, 6, 8 }
i := 0
s.Each(func(v interface{}) {
Printf("%v: %vn", i, v)
i++
})
}
91Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
type Iterable interface {
Each(func(interface{}))
}
type IterableSlice []int
func (i IterableSlice) Each(f func(interface{})) {
for _, v := range i {
f(v)
}
}
func main() {
var s Iterable = IterableSlice{ 0, 2, 4, 6, 8 }
i := 0
s.Each(func(v interface{}) {
Printf("%v: %vn", i, v)
i++
})
}
92Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
type Iterable interface {
Each(func(interface{}))
}
type IterableSlice []int
func (i IterableSlice) Each(f func(interface{})) {
for _, v := range i {
f(v)
}
}
func main() {
var s Iterable = IterableSlice{ 0, 2, 4, 6, 8 }
i := 0
s.Each(func(v interface{}) {
Printf("%v: %vn", i, v)
i++
})
}
93Going Loopy http://slides.games-with-brains.net/
package main
import . "fmt"
type Iterable interface {
Each(func(interface{}))
}
type IterableLimit int
func (i IterableLimit) Each(f func(interface{})) {
for v := 0; v < i; v++ {
f(v)
}
}
func main() {
var s Iterable = IterableLimit(5)
i := 0
s.Each(func(v interface{}) {
Printf("%v: %vn", i, v)
i++
})
}
94Going Loopy http://slides.games-with-brains.net/
AND YES, I DO
HAVE A BOOK
IN THE WORKS
IF THAT'S
YOUR THING
leanpub://GoNotebook

More Related Content

What's hot (20)

PDF
Clustering com numpy e cython
Anderson Dantas
 
PDF
Testing CLI tools with Go
Ricardo Gerardi
 
PDF
Go for the paranoid network programmer
Eleanor McHugh
 
KEY
Meck
Adam Lindberg
 
PDF
Python Peculiarities
noamt
 
PDF
Python于Web 2.0网站的应用 - QCon Beijing 2010
Qiangning Hong
 
PDF
Go for the would be network programmer
Eleanor McHugh
 
PDF
Call Return Exploration
Pat Hawks
 
PDF
The Ring programming language version 1.4 book - Part 15 of 30
Mahmoud Samir Fayed
 
PDF
EUnit in Practice(Japanese)
Yoshiki Shibukawa
 
PDF
Calling Functions
Pat Hawks
 
PDF
Python for High School Programmers
Siva Arunachalam
 
PDF
EuroPython 2015 - Decorators demystified
Pablo Enfedaque
 
PDF
Meck at erlang factory, london 2011
Adam Lindberg
 
PDF
FPBrno 2018-05-22: Benchmarking in elixir
Functional Programming Brno
 
PDF
The Browser Environment - A Systems Programmer's Perspective
Eleanor McHugh
 
PDF
Bai Giang 11
nbb3i
 
PPTX
Simple swing programs
vishal choudhary
 
DOCX
Application Form
Kapil Pandit
 
PDF
Go for the paranoid network programmer, 3rd edition
Eleanor McHugh
 
Clustering com numpy e cython
Anderson Dantas
 
Testing CLI tools with Go
Ricardo Gerardi
 
Go for the paranoid network programmer
Eleanor McHugh
 
Python Peculiarities
noamt
 
Python于Web 2.0网站的应用 - QCon Beijing 2010
Qiangning Hong
 
Go for the would be network programmer
Eleanor McHugh
 
Call Return Exploration
Pat Hawks
 
The Ring programming language version 1.4 book - Part 15 of 30
Mahmoud Samir Fayed
 
EUnit in Practice(Japanese)
Yoshiki Shibukawa
 
Calling Functions
Pat Hawks
 
Python for High School Programmers
Siva Arunachalam
 
EuroPython 2015 - Decorators demystified
Pablo Enfedaque
 
Meck at erlang factory, london 2011
Adam Lindberg
 
FPBrno 2018-05-22: Benchmarking in elixir
Functional Programming Brno
 
The Browser Environment - A Systems Programmer's Perspective
Eleanor McHugh
 
Bai Giang 11
nbb3i
 
Simple swing programs
vishal choudhary
 
Application Form
Kapil Pandit
 
Go for the paranoid network programmer, 3rd edition
Eleanor McHugh
 

Similar to Going Loopy - Adventures in Iteration with Google Go (20)

PDF
going loopy - adventures in iteration with go - Eleanor McHugh - Codemotion M...
Codemotion
 
PDF
going loopy - adventures in iteration with google go
Eleanor McHugh
 
PDF
An introduction to functional programming with go
Eleanor McHugh
 
PDF
Introduction to Go for Java Programmers
Kalpa Pathum Welivitigoda
 
ODP
Pick up the low-hanging concurrency fruit
Vaclav Pech
 
PDF
Python-GTK
Yuren Ju
 
PPTX
Jvm a brief introduction
Artem Shoobovych
 
PPTX
Golang basics for Java developers - Part 1
Robert Stern
 
PDF
Twig Templating
Rj Bautista
 
PDF
Advanced Debugging Using Java Bytecodes
Ganesh Samarthyam
 
PDF
The Ring programming language version 1.5.4 book - Part 10 of 185
Mahmoud Samir Fayed
 
PDF
Goptuna Distributed Bayesian Optimization Framework at Go Conference 2019 Autumn
Masashi Shibata
 
PPTX
Python 표준 라이브러리
용 최
 
PPTX
ภาษาซีพื้นฐาน
Krunee Thitthamon
 
PDF
Implementing Software Machines in Go and C
Eleanor McHugh
 
PDF
python codes
tusharpanda88
 
PPTX
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Domenic Denicola
 
PDF
Functional programming basics
openbala
 
PDF
Marrow: A Meta-Framework for Python 2.6+ and 3.1+
ConFoo
 
going loopy - adventures in iteration with go - Eleanor McHugh - Codemotion M...
Codemotion
 
going loopy - adventures in iteration with google go
Eleanor McHugh
 
An introduction to functional programming with go
Eleanor McHugh
 
Introduction to Go for Java Programmers
Kalpa Pathum Welivitigoda
 
Pick up the low-hanging concurrency fruit
Vaclav Pech
 
Python-GTK
Yuren Ju
 
Jvm a brief introduction
Artem Shoobovych
 
Golang basics for Java developers - Part 1
Robert Stern
 
Twig Templating
Rj Bautista
 
Advanced Debugging Using Java Bytecodes
Ganesh Samarthyam
 
The Ring programming language version 1.5.4 book - Part 10 of 185
Mahmoud Samir Fayed
 
Goptuna Distributed Bayesian Optimization Framework at Go Conference 2019 Autumn
Masashi Shibata
 
Python 표준 라이브러리
용 최
 
ภาษาซีพื้นฐาน
Krunee Thitthamon
 
Implementing Software Machines in Go and C
Eleanor McHugh
 
python codes
tusharpanda88
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Domenic Denicola
 
Functional programming basics
openbala
 
Marrow: A Meta-Framework for Python 2.6+ and 3.1+
ConFoo
 
Ad

More from Eleanor McHugh (20)

PDF
Y - Recursion The Hard Way GopherCon EU 2025
Eleanor McHugh
 
PDF
Never Say, Never Say Die! - the art of low-level Ruby and other Macabre Tales
Eleanor McHugh
 
PDF
[2024] An Introduction to Functional Programming with Go [Y Combinator Remix]...
Eleanor McHugh
 
PDF
[2023] Putting the R! in R&D.pdf
Eleanor McHugh
 
PDF
Generics, Reflection, and Efficient Collections
Eleanor McHugh
 
PDF
The Relevance of Liveness - Biometrics and Data Integrity
Eleanor McHugh
 
PDF
The Browser Environment - A Systems Programmer's Perspective [sinatra edition]
Eleanor McHugh
 
PDF
An introduction to functional programming with Go [redux]
Eleanor McHugh
 
PDF
Implementing virtual machines in go & c 2018 redux
Eleanor McHugh
 
PDF
Identity & trust in Monitored Spaces
Eleanor McHugh
 
PDF
Don't Ask, Don't Tell - The Virtues of Privacy By Design
Eleanor McHugh
 
PDF
Don't ask, don't tell the virtues of privacy by design
Eleanor McHugh
 
PDF
Anonymity, identity, trust
Eleanor McHugh
 
PDF
Distributed Ledgers: Anonymity & Immutability at Scale
Eleanor McHugh
 
PDF
Finding a useful outlet for my many Adventures in go
Eleanor McHugh
 
PDF
Anonymity, trust, accountability
Eleanor McHugh
 
PDF
Implementing Virtual Machines in Ruby & C
Eleanor McHugh
 
PDF
Implementing Software Machines in C and Go
Eleanor McHugh
 
PDF
Encrypt all transports
Eleanor McHugh
 
PDF
Whispered secrets
Eleanor McHugh
 
Y - Recursion The Hard Way GopherCon EU 2025
Eleanor McHugh
 
Never Say, Never Say Die! - the art of low-level Ruby and other Macabre Tales
Eleanor McHugh
 
[2024] An Introduction to Functional Programming with Go [Y Combinator Remix]...
Eleanor McHugh
 
[2023] Putting the R! in R&D.pdf
Eleanor McHugh
 
Generics, Reflection, and Efficient Collections
Eleanor McHugh
 
The Relevance of Liveness - Biometrics and Data Integrity
Eleanor McHugh
 
The Browser Environment - A Systems Programmer's Perspective [sinatra edition]
Eleanor McHugh
 
An introduction to functional programming with Go [redux]
Eleanor McHugh
 
Implementing virtual machines in go & c 2018 redux
Eleanor McHugh
 
Identity & trust in Monitored Spaces
Eleanor McHugh
 
Don't Ask, Don't Tell - The Virtues of Privacy By Design
Eleanor McHugh
 
Don't ask, don't tell the virtues of privacy by design
Eleanor McHugh
 
Anonymity, identity, trust
Eleanor McHugh
 
Distributed Ledgers: Anonymity & Immutability at Scale
Eleanor McHugh
 
Finding a useful outlet for my many Adventures in go
Eleanor McHugh
 
Anonymity, trust, accountability
Eleanor McHugh
 
Implementing Virtual Machines in Ruby & C
Eleanor McHugh
 
Implementing Software Machines in C and Go
Eleanor McHugh
 
Encrypt all transports
Eleanor McHugh
 
Whispered secrets
Eleanor McHugh
 
Ad

Recently uploaded (20)

PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
TrustArc Webinar - Navigating Data Privacy in LATAM: Laws, Trends, and Compli...
TrustArc
 
PDF
Basics of Electronics for IOT(actuators ,microcontroller etc..)
arnavmanesh
 
PDF
Researching The Best Chat SDK Providers in 2025
Ray Fields
 
PDF
introduction to computer hardware and sofeware
chauhanshraddha2007
 
PDF
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
 
PPTX
python advanced data structure dictionary with examples python advanced data ...
sprasanna11
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
PDF
Market Insight : ETH Dominance Returns
CIFDAQ
 
PDF
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
PDF
Lecture A - AI Workflows for Banking.pdf
Dr. LAM Yat-fai (林日辉)
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PDF
Per Axbom: The spectacular lies of maps
Nexer Digital
 
PDF
The Past, Present & Future of Kenya's Digital Transformation
Moses Kemibaro
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PDF
How Current Advanced Cyber Threats Transform Business Operation
Eryk Budi Pratama
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
TrustArc Webinar - Navigating Data Privacy in LATAM: Laws, Trends, and Compli...
TrustArc
 
Basics of Electronics for IOT(actuators ,microcontroller etc..)
arnavmanesh
 
Researching The Best Chat SDK Providers in 2025
Ray Fields
 
introduction to computer hardware and sofeware
chauhanshraddha2007
 
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
 
python advanced data structure dictionary with examples python advanced data ...
sprasanna11
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
Market Insight : ETH Dominance Returns
CIFDAQ
 
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
Lecture A - AI Workflows for Banking.pdf
Dr. LAM Yat-fai (林日辉)
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
Per Axbom: The spectacular lies of maps
Nexer Digital
 
The Past, Present & Future of Kenya's Digital Transformation
Moses Kemibaro
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
How Current Advanced Cyber Threats Transform Business Operation
Eryk Budi Pratama
 
Simple and concise overview about Quantum computing..pptx
mughal641
 

Going Loopy - Adventures in Iteration with Google Go

  • 1. going loopy adventures in iteration with google go @feyeleanor Going Loopy http://slideshare.net/feyeleanor/1
  • 2. the task Going Loopy http://slides.games-with-brains.net/2
  • 3. 0: 0 1: 2 2: 4 3: 6 4: 8 Going Loopy http://slides.games-with-brains.net/3
  • 4. the conditional loop Going Loopy http://slides.games-with-brains.net/4
  • 5. package main import "fmt" func main() { s := []int{0, 2, 4, 6, 8} for i := 0; i < len(s); i++ { fmt.Printf("%v: %vn", i, s[i]) } } Going Loopy http://slides.games-with-brains.net/5
  • 6. package main import "fmt" func main() { s := []int{0, 2, 4, 6, 8} for i := 0; i < len(s); i++ { fmt.Printf("%v: %vn", i, s[i]) } } Going Loopy http://slides.games-with-brains.net/6
  • 7. package main import . "fmt" func main() { s := []int{0, 2, 4, 6, 8} for i := 0; i < len(s); i++ { Printf("%v: %vn", i, s[i]) } } 7Going Loopy http://slides.games-with-brains.net/
  • 8. package main import . "fmt" func main() { s := []int{0, 2, 4, 6, 8} for i := 0; i < len(s); i++ { Printf("%v: %vn", i, s[i]) } } 8Going Loopy http://slides.games-with-brains.net/
  • 9. package main import . "fmt" func main() { s := []int{0, 2, 4, 6, 8} for i := 0; i < len(s); i++ { Printf("%v: %vn", i, s[i]) } } 9Going Loopy http://slides.games-with-brains.net/
  • 10. package main import . "fmt" func main() { s := []int{0, 2, 4, 6, 8} for i := 0; i < len(s); i++ { Printf("%v: %vn", i, s[i]) } } Going Loopy http://slides.games-with-brains.net/10
  • 11. package main import . "fmt" func main() { s := []int{0, 2, 4, 6, 8} for i := 0; i < len(s); i++ { Printf("%v: %vn", i, s[i]) } } Going Loopy http://slides.games-with-brains.net/11
  • 12. package main import . "fmt" func main() { s := []int{0, 2, 4, 6, 8} for i := 0; i < len(s); i++ { Printf("%v: %vn", i, s[i]) } } Going Loopy http://slides.games-with-brains.net/12
  • 13. package main import . "fmt" func main() { s := []int{0, 2, 4, 6, 8} for i := 0; i < len(s); i++ { Printf("%v: %vn", i, s[i]) } } Going Loopy http://slides.games-with-brains.net/13
  • 14. package main import . "fmt" func main() { s := []int{0, 2, 4, 6, 8} for i := 0; i < len(s); i++ { Printf("%v: %vn", i, s[i]) } } Going Loopy http://slides.games-with-brains.net/14
  • 15. package main import . "fmt" func main() { s := []int{0, 2, 4, 6, 8} for i := 0; i < len(s); i++ { Printf("%v: %vn", i, s[i]) } } Going Loopy http://slides.games-with-brains.net/15
  • 16. package main import . "fmt" func main() { s := []int{0, 2, 4, 6, 8} for i := 0; i < len(s); i++ { Printf("%v: %vn", i, s[i]) } } Going Loopy http://slides.games-with-brains.net/16
  • 17. package main import . "fmt" func main() { s := []int{0, 2, 4, 6, 8} for i := 0; i < len(s); i++ { Printf("%v: %vn", i, s[i]) } } 17Going Loopy http://slides.games-with-brains.net/
  • 18. package main import . "fmt" func main() { s := []int{0, 2, 4, 6, 8} for i := 0; i < len(s); i++ { Printf("%v: %vn", i, s[i]) } } Going Loopy http://slides.games-with-brains.net/18
  • 19. package main import . "fmt" func main() { s := []int{0, 2, 4, 6, 8} for i := 0; i < len(s); i++ { Printf("%v: %vn", i, s[i]) } } Going Loopy http://slides.games-with-brains.net/19
  • 20. package main import . "fmt" func main() { s := []int{0, 2, 4, 6, 8} for i := 0; i < len(s); i++ { Printf("%v: %vn", i, s[i]) } } Going Loopy http://slides.games-with-brains.net/20
  • 21. package main import . "fmt" func main() { s := []int{0, 2, 4, 6, 8} for i := 0; i < len(s); i++ { Printf("%v: %vn", i, s[i]) } } Going Loopy http://slides.games-with-brains.net/21
  • 22. the infinite loop Going Loopy http://slides.games-with-brains.net/22
  • 23. package main import . "fmt" func main() { defer func() { recover() }() s := []int{0, 2, 4, 6, 8} i := 0 for { Printf("%v: %vn", i, s[i]) i++ } } Going Loopy http://slides.games-with-brains.net/23
  • 24. package main import . "fmt" func main() { defer func() { recover() }() s := []int{0, 2, 4, 6, 8} i := 0 for { Printf("%v: %vn", i, s[i]) i++ } } Going Loopy http://slides.games-with-brains.net/24
  • 25. package main import . "fmt" func main() { defer func() { recover() }() s := []int{0, 2, 4, 6, 8} i := 0 for { Printf("%v: %vn", i, s[i]) i++ } } Going Loopy http://slides.games-with-brains.net/25
  • 26. package main import . "fmt" func main() { defer func() { recover() }() s := []int{0, 2, 4, 6, 8} i := 0 for { Printf("%v: %vn", i, s[i]) i++ } } Going Loopy http://slides.games-with-brains.net/26
  • 27. package main import . "fmt" func main() { defer func() { recover() }() s := []int{0, 2, 4, 6, 8} i := 0 for { Printf("%v: %vn", i, s[i]) i++ } } Going Loopy http://slides.games-with-brains.net/27
  • 28. package main import . "fmt" func main() { defer func() { recover() }() s := []int{0, 2, 4, 6, 8} i := 0 for i := 0; ; i++ { Printf("%v: %vn", i, s[i]) i++ } } Going Loopy http://slides.games-with-brains.net/28
  • 29. the range Going Loopy http://slides.games-with-brains.net/29
  • 30. package main import . "fmt" func main() { s := []int{0, 2, 4, 6, 8} for i, v := range s { Printf("%v: %vn", i, v) } } Going Loopy http://slides.games-with-brains.net/30
  • 31. package main import . "fmt" func main() { s := []int{0, 2, 4, 6, 8} for i, v := range s { Printf("%v: %vn", i, v) } } Going Loopy http://slides.games-with-brains.net/31
  • 32. package main import . "fmt" func main() { s := []int{0, 2, 4, 6, 8} for i, v := range s { Printf("%v: %vn", i, v) } } Going Loopy http://slides.games-with-brains.net/32
  • 33. package main import . "fmt" func main() { s := []int{0, 2, 4, 6, 8} for i, v := range s { Printf("%v: %vn", i, v) } } Going Loopy http://slides.games-with-brains.net/33
  • 34. package main import . "fmt" func main() { s := []int{0, 2, 4, 6, 8} for i, v := range s { Printf("%v: %vn", i, v) } } Going Loopy http://slides.games-with-brains.net/34
  • 35. a functional interlude 35Going Loopy http://slides.games-with-brains.net/
  • 36. package main import . "fmt" func main() { print_slice([]int{0, 2, 4, 6, 8}) } func print_slice(s []int) { for i, v := range s { Printf("%v: %vn", i, v) } } 36Going Loopy http://slides.games-with-brains.net/
  • 37. package main import . "fmt" func main() { print_slice([]int{0, 2, 4, 6, 8}) } func print_slice(s []int) { for i, v := range s { Printf("%v: %vn", i, v) } } 37Going Loopy http://slides.games-with-brains.net/
  • 38. package main import . "fmt" func main() { print_slice([]int{0, 2, 4, 6, 8}) } func print_slice(s []int) { for i, v := range s { Printf("%v: %vn", i, v) } } 38Going Loopy http://slides.games-with-brains.net/
  • 39. package main import . "fmt" func main() { print_slice(0, 2, 4, 6, 8) } func print_slice(s ...int) { for i, v := range s { Printf("%v: %vn", i, v) } } 39Going Loopy http://slides.games-with-brains.net/
  • 40. asserting type Going Loopy http://slides.games-with-brains.net/40
  • 41. package main import . "fmt" func main() { print_slice([]int{0, 2, 4, 6, 8}) } func print_slice(s interface{}) { for i, v := range s.([]int) { Printf("%v: %vn", i, v) } } Going Loopy http://slides.games-with-brains.net/41
  • 42. package main import . "fmt" func main() { print_slice([]int{0, 2, 4, 6, 8}) } func print_slice(s interface{}) { for i, v := range s.([]int) { Printf("%v: %vn", i, v) } } Going Loopy http://slides.games-with-brains.net/42
  • 43. package main import . "fmt" func main() { print_slice([]int{0, 2, 4, 6, 8}) } func print_slice(s interface{}) { if s, ok := s.([]int); ok { for i, v := range s { Printf("%v: %vn", i, v) } } } Going Loopy http://slides.games-with-brains.net/43
  • 44. package main import . "fmt" func main() { print_slice([]int{0, 2, 4, 6, 8}) } func print_slice(s interface{}) { if s, ok := s.([]int); ok { for i, v := range s { Printf("%v: %vn", i, v) } } } Going Loopy http://slides.games-with-brains.net/44
  • 45. package main import . "fmt" func main() { print_slice([]int{0, 2, 4, 6, 8}) } func print_slice(s interface{}) { if s, ok := s.([]int); ok { for i, v := range s { Printf("%v: %vn", i, v) } } } Going Loopy http://slides.games-with-brains.net/45
  • 46. package main import . "fmt" func main() { print_slice([]int{0, 2, 4, 6, 8}) } func print_slice(s interface{}) { if s, ok := s.([]int); ok { for i, v := range s { Printf("%v: %vn", i, v) } } } Going Loopy http://slides.games-with-brains.net/46
  • 47. package main import . "fmt" func main() { print_slice([]int{0, 2, 4, 6, 8}) } func print_slice(s interface{}) { switch s := s.(type) { case []int: for i, v := range s { Printf("%v: %vn", i, v) } } } Going Loopy http://slides.games-with-brains.net/47
  • 48. package main import . "fmt" func main() { print_slice([]int{0, 2, 4, 6, 8}) } func print_slice(s interface{}) { switch s := s.(type) { case []int: for i, v := range s { Printf("%v: %vn", i, v) } } } Going Loopy http://slides.games-with-brains.net/48
  • 49. package main import . "fmt" func main() { print_slice([]int{0, 2, 4, 6, 8}) } func print_slice(s interface{}) { switch s := s.(type) { case []int: for i, v := range s { Printf("%v: %vn", i, v) } } } Going Loopy http://slides.games-with-brains.net/49
  • 51. package main import . "fmt" func main() { s := []int{0, 2, 4, 6, 8} print_slice(func(i int) int { return s[i] }) } func print_slice(s interface{}) { switch s := s.(type) { case func(int) int: for i := 0; i < 5; i++ { Printf("%v: %vn", i, s(i)) } } } 51Going Loopy http://slides.games-with-brains.net/
  • 52. package main import . "fmt" func main() { s := []int{0, 2, 4, 6, 8} print_slice(func(i int) int { return s[i] }) } func print_slice(s interface{}) { switch s := s.(type) { case func(int) int: for i := 0; i < 5; i++ { Printf("%v: %vn", i, s(i)) } } } 52Going Loopy http://slides.games-with-brains.net/
  • 53. package main import . "fmt" func main() { s := []int{0, 2, 4, 6, 8} print_slice(func(i int) int { return s[i] }) } func print_slice(s interface{}) { switch s := s.(type) { case func(int) int: for i := 0; i < 5; i++ { Printf("%v: %vn", i, s(i)) } } } 53Going Loopy http://slides.games-with-brains.net/
  • 54. package main import . "fmt" func main() { s := []int{0, 2, 4, 6, 8} print_slice(func(i int) int { return s[i] }) } func print_slice(s interface{}) { switch s := s.(type) { case func(int) int: for i := 0; i < 5; i++ { Printf("%v: %vn", i, s(i)) } } } 54Going Loopy http://slides.games-with-brains.net/
  • 55. package main import . "fmt" func main() { s := []int{0, 2, 4, 6, 8} print_slice(func(i int) int { return s[i] }) } func print_slice(s interface{}) { switch s := s.(type) { case func(int) int: for i := 0; i < 5; i++ { Printf("%v: %vn", i, s(i)) } } } 55Going Loopy http://slides.games-with-brains.net/
  • 56. package main import . "fmt" func main() { s := []int{0, 2, 4, 6, 8} print_slice(func(i int) int { return s[i] }) } func print_slice(s interface{}) { switch s := s.(type) { case func(int) int: for i := 0; i < 5; i++ { Printf("%v: %vn", i, s(i)) } } } 56Going Loopy http://slides.games-with-brains.net/
  • 57. package main import . "fmt" func main() { s := []int{0, 2, 4, 6, 8} print_slice(func(i int) int { return s[i] }) } func print_slice(s interface{}) { switch s := s.(type) { case func(int) int: for i := 0; i < 5; i++ { Printf("%v: %vn", i, s(i)) } } } 57Going Loopy http://slides.games-with-brains.net/
  • 59. package main import . "fmt" func main() { c := make(chan int) go func() { for _, v := range []int{0, 2, 4, 6, 8} { c <- v } close(c) }() Printf("elements: %vn", print_channel(c)) } func print_channel(c chan int) (i int) { for v := range c { Printf("%v: %vn", i, v) i++ } return } 59Going Loopy http://slides.games-with-brains.net/
  • 60. package main import . "fmt" func main() { c := make(chan int, 16) go func() { for _, v := range []int{0, 2, 4, 6, 8} { c <- v } close(c) }() Printf("elements: %vn", print_channel(c)) } func print_channel(c chan int) (i int) { for v := range c { Printf("%v: %vn", i, v) i++ } return } 60Going Loopy http://slides.games-with-brains.net/
  • 61. package main import . "fmt" func main() { c := make(chan int) go func() { for _, v := range []int{0, 2, 4, 6, 8} { c <- v } close(c) }() Printf("elements: %vn", print_channel(c)) } func print_channel(c chan int) (i int) { for v := range c { Printf("%v: %vn", i, v) i++ } return } 61Going Loopy http://slides.games-with-brains.net/
  • 62. package main import . "fmt" func main() { c := make(chan int) go func() { for _, v := range []int{0, 2, 4, 6, 8} { c <- v } close(c) }() Printf("elements: %vn", print_channel(c)) } func print_channel(c chan int) (i int) { for v := range c { Printf("%v: %vn", i, v) i++ } return } 62Going Loopy http://slides.games-with-brains.net/
  • 63. package main import . "fmt" func main() { c := make(chan int) go func() { for _, v := range []int{0, 2, 4, 6, 8} { c <- v } close(c) }() Printf("elements: %vn", print_channel(c)) } func print_channel(c chan int) (i int) { for v := range c { Printf("%v: %vn", i, v) i++ } return } 63Going Loopy http://slides.games-with-brains.net/
  • 64. package main import . "fmt" func main() { c := make(chan int) go func() { for _, v := range []int{0, 2, 4, 6, 8} { c <- v } close(c) }() Printf("elements: %vn", print_channel(c)) } func print_channel(c chan int) (i int) { for v := range c { Printf("%v: %vn", i, v) i++ } return } 64Going Loopy http://slides.games-with-brains.net/
  • 65. package main import . "fmt" func main() { c := make(chan int) go func() { for _, v := range []int{0, 2, 4, 6, 8} { c <- v } close(c) }() Printf("elements: %vn", print_channel(c)) } func print_channel(c chan int) (i int) { for v := range c { Printf("%v: %vn", i, v) i++ } return } 65Going Loopy http://slides.games-with-brains.net/
  • 66. package main import . "fmt" func main() { c := make(chan int) go func() { for _, v := range []int{0, 2, 4, 6, 8} { c <- v } close(c) }() Printf("elements: %vn", print_channel(c)) } func print_channel(c chan int) (i int) { for v := range c { Printf("%v: %vn", i, v) i++ } return } 66Going Loopy http://slides.games-with-brains.net/
  • 67. package main import . "fmt" func main() { c := make(chan int) go func() { for _, v := range []int{0, 2, 4, 6, 8} { c <- v } close(c) }() Printf("elements: %vn", print_channel(c)) } func print_channel(c chan int) (i int) { for v := range c { Printf("%v: %vn", i, v) i++ } return } 67Going Loopy http://slides.games-with-brains.net/
  • 68. upon reflection 68Going Loopy http://slides.games-with-brains.net/
  • 69. package main import . "fmt" func main() { s := []int{0, 2, 4, 6, 8} print_values(s) print_values(func(i int) int { return s[i] }) } func print_values(s interface{}) { switch s := s.(type) { case func(int) int: for i := 0; i < 5; i++ { Printf("%v: %vn", i, s(i)) } case []int: for i, v := range s { Printf("%v: %vn", i, v) } } } 69Going Loopy http://slides.games-with-brains.net/
  • 70. package main import . "fmt" func main() { s := []int{0, 2, 4, 6, 8} print_values(s) print_values(func(i int) int { return s[i] }) } func print_values(s interface{}) { switch s := s.(type) { case func(int) int: for i := 0; i < 5; i++ { Printf("%v: %vn", i, s(i)) } case []int: for i, v := range s { Printf("%v: %vn", i, v) } } } 70Going Loopy http://slides.games-with-brains.net/
  • 71. package main import . "fmt" func main() { s := []int{0, 2, 4, 6, 8} print_values(s) print_values(func(i int) int { return s[i] }) } func print_values(s interface{}) { switch s := s.(type) { case func(int) int: for i := 0; i < 5; i++ { Printf("%v: %vn", i, s(i)) } case []int: for i, v := range s { Printf("%v: %vn", i, v) } } } 71Going Loopy http://slides.games-with-brains.net/
  • 72. package main import . "fmt" import "reflect" func main() { s := []int{0, 2, 4, 6, 8} print_values(s) print_values(func(i int) int { return s[i] }) } func print_values(s interface{}) { switch s := reflect.ValueOf(s); s.Kind() { case reflect.Func: for i := 0; i < 5; i++ { p := []reflect.Value{ reflect.ValueOf(i) } Printf("%v: %vn", i, s.Call(p)[0].Interface{}) } case reflect.Slice: for i := 0; i < s.Len(); i++ { Printf("%v: %vn", i, s.Index(i)) } } } 72Going Loopy http://slides.games-with-brains.net/
  • 73. package main import . "fmt" import "reflect" func main() { s := []int{0, 2, 4, 6, 8} print_values(s) print_values(func(i int) int { return s[i] }) } func print_values(s interface{}) { switch s := reflect.ValueOf(s); s.Kind() { case reflect.Func: for i := 0; i < 5; i++ { p := []reflect.Value{ reflect.ValueOf(i) } Printf("%v: %vn", i, s.Call(p)[0].Interface()) } case reflect.Slice: for i := 0; i < s.Len(); i++ { Printf("%v: %vn", i, s.Index(i).Interface()) } } } 73Going Loopy http://slides.games-with-brains.net/
  • 74. package main import . "fmt" import "reflect" func main() { s := []int{0, 2, 4, 6, 8} print_values(s) print_values(func(i int) int { return s[i] }) } func print_values(s interface{}) { switch s := reflect.ValueOf(s); s.Kind() { case reflect.Func: for i := 0; i < 5; i++ { p := []reflect.Value{ reflect.ValueOf(i) } Printf("%v: %vn", i, s.Call(p)[0].Interface()) } case reflect.Slice: for i := 0; i < s.Len(); i++ { Printf("%v: %vn", i, s.Index(i).Interface()) } } } 74Going Loopy http://slides.games-with-brains.net/
  • 75. package main import . "fmt" import "reflect" func main() { s := []int{0, 2, 4, 6, 8} print_values(s) print_values(func(i int) int { return s[i] }) } func print_values(s interface{}) { switch s := reflect.ValueOf(s); s.Kind() { case reflect.Func: for i := 0; i < 5; i++ { p := []reflect.Value{ reflect.ValueOf(i) } Printf("%v: %vn", i, s.Call(p)[0].Interface()) } case reflect.Slice: for i := 0; i < s.Len(); i++ { Printf("%v: %vn", i, s.Index(i).Interface()) } } } 75Going Loopy http://slides.games-with-brains.net/
  • 76. package main import . "fmt" import "reflect" func main() { s := []int{0, 2, 4, 6, 8} print_values(s) print_values(func(i int) int { return s[i] }) } func print_values(s interface{}) { switch s := reflect.ValueOf(s); s.Kind() { case reflect.Func: for i := 0; i < 5; i++ { p := []reflect.Value{ reflect.ValueOf(i) } Printf("%v: %vn", i, s.Call(p)[0].Interface()) } case reflect.Slice: for i := 0; i < s.Len(); i++ { Printf("%v: %vn", i, s.Index(i).Interface()) } } } 76Going Loopy http://slides.games-with-brains.net/
  • 77. package main import . "fmt" import . "reflect" func main() { s := []int{0, 2, 4, 6, 8} print_values(s) print_values(func(i int) int { return s[i] }) } func print_values(s interface{}) { switch s := ValueOf(s); s.Kind() { case Func: for i := 0; i < 5; i++ { p := []Value{ ValueOf(i) } Printf("%v: %vn", i, s.Call(p)[0].Interface()) } case Slice: for i := 0; i < s.Len(); i++ { Printf("%v: %vn", i, s.Index(i).Interface()) } } } 77Going Loopy http://slides.games-with-brains.net/
  • 78. package main import . "fmt" import . "reflect" func main() { s := []int{0, 2, 4, 6, 8} print_values(s) print_values(func(i int) int { return s[i] }) } func print_values(s interface{}) { switch s := ValueOf(s); s.Kind() { case Func: for i := 0; i < 5; i++ { p := []Value{ ValueOf(i) } Printf("%v: %vn", i, s.Call(p)[0].Interface()) } case Slice: for i := 0; i < s.Len(); i++ { Printf("%v: %vn", i, s.Index(i).Interface()) } } } 78Going Loopy http://slides.games-with-brains.net/
  • 79. package main import . "fmt" import . "reflect" func main() { s := []int{0, 2, 4, 6, 8} print_values(s) print_values(func(i int) int { return s[i] }) } func print_values(s interface{}) { switch s := ValueOf(s); s.Kind() { case Func: for i := 0; i < 5; i++ { p := []Value{ ValueOf(i) } Printf("%v: %vn", i, s.Call(p)[0].Interface()) } case Slice: for i := 0; i < s.Len(); i++ { Printf("%v: %vn", i, s.Index(i).Interface()) } } } 79Going Loopy http://slides.games-with-brains.net/
  • 80. package main import . "fmt" import . "reflect" func main() { s := []int{0, 2, 4, 6, 8} print_values(s) print_values(func(i int) int { return s[i] }) } func print_values(s interface{}) { switch s := ValueOf(s); s.Kind() { case Func: for i := 0; i < 5; i++ { p := []Value{ ValueOf(i) } Printf("%v: %vn", i, s.Call(p)[0].Interface()) } case Slice: for i := 0; i < s.Len(); i++ { Printf("%v: %vn", i, s.Index(i).Interface()) } } } 80Going Loopy http://slides.games-with-brains.net/
  • 81. package main import . "fmt" import . "reflect" func main() { s := []int{0, 2, 4, 6, 8} print_values(s) print_values(func(i int) int { return s[i] }) } func print_values(s interface{}) { switch s := ValueOf(s); s.Kind() { case Func: for i := 0; i < 5; i++ { p := []Value{ ValueOf(i) } Printf("%v: %vn", i, s.Call(p)[0].Interface()) } case Slice: for i := 0; i < s.Len(); i++ { Printf("%v: %vn", i, s.Index(i).Interface()) } } } 81Going Loopy http://slides.games-with-brains.net/
  • 82. user-defined type 82Going Loopy http://slides.games-with-brains.net/
  • 83. package main import . "fmt" type IterableSlice []int func (i IterableSlice) Each(f func(interface{})) { for _, v := range i { f(v) } } func main() { s := IterableSlice{ 0, 2, 4, 6, 8 } i := 0 s.Each(func(v interface{}) { Printf("%v: %vn", i, v) i++ }) } 83Going Loopy http://slides.games-with-brains.net/
  • 84. package main import . "fmt" type IterableSlice []int func (i IterableSlice) Each(f func(interface{})) { for _, v := range i { f(v) } } func main() { s := IterableSlice{ 0, 2, 4, 6, 8 } i := 0 s.Each(func(v interface{}) { Printf("%v: %vn", i, v) i++ }) } 84Going Loopy http://slides.games-with-brains.net/
  • 85. package main import . "fmt" type IterableSlice []int func (i IterableSlice) Each(f func(interface{})) { for _, v := range i { f(v) } } func main() { s := IterableSlice{ 0, 2, 4, 6, 8 } i := 0 s.Each(func(v interface{}) { Printf("%v: %vn", i, v) i++ }) } 85Going Loopy http://slides.games-with-brains.net/
  • 86. package main import . "fmt" type IterableSlice []int func (i IterableSlice) Each(f func(interface{})) { for _, v := range i { f(v) } } func main() { s := IterableSlice{ 0, 2, 4, 6, 8 } i := 0 s.Each(func(v interface{}) { Printf("%v: %vn", i, v) i++ }) } 86Going Loopy http://slides.games-with-brains.net/
  • 87. package main import . "fmt" type IterableSlice []int func (i IterableSlice) Each(f func(interface{})) { for _, v := range i { f(v) } } func main() { s := IterableSlice{ 0, 2, 4, 6, 8 } i := 0 s.Each(func(v interface{}) { Printf("%v: %vn", i, v) i++ }) } 87Going Loopy http://slides.games-with-brains.net/
  • 88. package main import . "fmt" type IterableSlice []int func (i IterableSlice) Each(f func(interface{})) { for _, v := range i { f(v) } } func main() { s := IterableSlice{ 0, 2, 4, 6, 8 } i := 0 s.Each(func(v interface{}) { Printf("%v: %vn", i, v) i++ }) } 88Going Loopy http://slides.games-with-brains.net/
  • 89. package main import . "fmt" type IterableSlice []int func (i IterableSlice) Each(f func(interface{})) { for _, v := range i { f(v) } } func main() { s := IterableSlice{ 0, 2, 4, 6, 8 } i := 0 s.Each(func(v interface{}) { Printf("%v: %vn", i, v) i++ }) } 89Going Loopy http://slides.games-with-brains.net/
  • 90. package main import . "fmt" type Iterable interface { Each(func(interface{})) } type IterableSlice []int func (i IterableSlice) Each(f func(interface{})) { for _, v := range i { f(v) } } func main() { var s Iterable = IterableSlice{ 0, 2, 4, 6, 8 } i := 0 s.Each(func(v interface{}) { Printf("%v: %vn", i, v) i++ }) } 90Going Loopy http://slides.games-with-brains.net/
  • 91. package main import . "fmt" type Iterable interface { Each(func(interface{})) } type IterableSlice []int func (i IterableSlice) Each(f func(interface{})) { for _, v := range i { f(v) } } func main() { var s Iterable = IterableSlice{ 0, 2, 4, 6, 8 } i := 0 s.Each(func(v interface{}) { Printf("%v: %vn", i, v) i++ }) } 91Going Loopy http://slides.games-with-brains.net/
  • 92. package main import . "fmt" type Iterable interface { Each(func(interface{})) } type IterableSlice []int func (i IterableSlice) Each(f func(interface{})) { for _, v := range i { f(v) } } func main() { var s Iterable = IterableSlice{ 0, 2, 4, 6, 8 } i := 0 s.Each(func(v interface{}) { Printf("%v: %vn", i, v) i++ }) } 92Going Loopy http://slides.games-with-brains.net/
  • 93. package main import . "fmt" type Iterable interface { Each(func(interface{})) } type IterableSlice []int func (i IterableSlice) Each(f func(interface{})) { for _, v := range i { f(v) } } func main() { var s Iterable = IterableSlice{ 0, 2, 4, 6, 8 } i := 0 s.Each(func(v interface{}) { Printf("%v: %vn", i, v) i++ }) } 93Going Loopy http://slides.games-with-brains.net/
  • 94. package main import . "fmt" type Iterable interface { Each(func(interface{})) } type IterableLimit int func (i IterableLimit) Each(f func(interface{})) { for v := 0; v < i; v++ { f(v) } } func main() { var s Iterable = IterableLimit(5) i := 0 s.Each(func(v interface{}) { Printf("%v: %vn", i, v) i++ }) } 94Going Loopy http://slides.games-with-brains.net/
  • 95. AND YES, I DO HAVE A BOOK IN THE WORKS IF THAT'S YOUR THING leanpub://GoNotebook