• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
going loopy - adventures in iteration with google go
 

going loopy - adventures in iteration with google go

on

  • 863 views

A sideways introduction to programming in go via the medium of for loops

A sideways introduction to programming in go via the medium of for loops

Statistics

Views

Total Views
863
Views on SlideShare
790
Embed Views
73

Actions

Likes
1
Downloads
17
Comments
0

1 Embed 73

https://twitter.com 73

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution-ShareAlike LicenseCC Attribution-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    going loopy - adventures in iteration with google go going loopy - adventures in iteration with google go Presentation Transcript

    • going loopy adventures in iteration with google go ! ! @feyeleanor Going Loopy !1 http://slideshare.net/feyeleanor/
    • the conditional loop Going Loopy !2 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++ { fmt.Printf("%v: %vn", i, s[i]) } } Going Loopy !3 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++ { fmt.Printf("%v: %vn", i, s[i]) } } ! ! 0: 1: 2: 3: 4: Going Loopy 0 2 4 6 8 !4 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++ { fmt.Printf("%v: %vn", i, s[i]) } } Going Loopy !5 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++ { fmt.Printf("%v: %vn", i, s[i]) } } Going Loopy !6 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++ { fmt.Printf("%v: %vn", i, s[i]) } } Going Loopy !7 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 !8 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 !9 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 !10 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 !11 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 !12 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 !13 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 !14 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 !15 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 !16 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 !17 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 !18 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 !19 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 !20 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 !21 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 !22 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 !23 http://slides.games-with-brains.net/
    • the infinite loop Going Loopy !24 http://slides.games-with-brains.net/
    • 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 !25 http://slides.games-with-brains.net/
    • 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 !26 http://slides.games-with-brains.net/
    • 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 !27 http://slides.games-with-brains.net/
    • 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 !28 http://slides.games-with-brains.net/
    • 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 !29 http://slides.games-with-brains.net/
    • 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 !30 http://slides.games-with-brains.net/
    • 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 !31 http://slides.games-with-brains.net/
    • the range Going Loopy !32 http://slides.games-with-brains.net/
    • 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 !33 http://slides.games-with-brains.net/
    • 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 !34 http://slides.games-with-brains.net/
    • 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 !35 http://slides.games-with-brains.net/
    • 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 !36 http://slides.games-with-brains.net/
    • 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 !37 http://slides.games-with-brains.net/
    • 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 !38 http://slides.games-with-brains.net/
    • a functional interlude Going Loopy !39 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) } } Going Loopy !40 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) } } Going Loopy !41 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) } } Going Loopy !42 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) } } Going Loopy !43 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) } } Going Loopy !44 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) } } Going Loopy !45 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) } } Going Loopy !46 http://slides.games-with-brains.net/
    • asserting type Going Loopy !47 http://slides.games-with-brains.net/
    • 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 !48 http://slides.games-with-brains.net/
    • 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 !49 http://slides.games-with-brains.net/
    • 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 !50 http://slides.games-with-brains.net/
    • 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 !51 http://slides.games-with-brains.net/
    • 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 !52 http://slides.games-with-brains.net/
    • 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 !53 http://slides.games-with-brains.net/
    • 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 !54 http://slides.games-with-brains.net/
    • 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 !55 http://slides.games-with-brains.net/
    • 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 !56 http://slides.games-with-brains.net/
    • 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 !57 http://slides.games-with-brains.net/
    • 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 !58 http://slides.games-with-brains.net/
    • 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 !59 http://slides.games-with-brains.net/
    • 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 !60 http://slides.games-with-brains.net/
    • 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 !61 http://slides.games-with-brains.net/
    • 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 !62 http://slides.games-with-brains.net/
    • closures Going Loopy !63 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)) } } } Going Loopy !64 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)) } } } Going Loopy !65 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)) } } } Going Loopy !66 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)) } } } Going Loopy !67 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)) } } } Going Loopy !68 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)) } } } Going Loopy !69 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)) } } } Going Loopy !70 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)) } } } Going Loopy !71 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)) } } } Going Loopy !72 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)) } } } Going Loopy !73 http://slides.games-with-brains.net/
    • channels Going Loopy !74 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 } Going Loopy !75 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 } Going Loopy !76 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 } Going Loopy !77 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 } Going Loopy !78 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 } Going Loopy !79 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 } Going Loopy !80 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 } Going Loopy !81 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 } Going Loopy !82 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 } Going Loopy !83 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 } Going Loopy !84 http://slides.games-with-brains.net/
    • upon reflection Going Loopy !85 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] * 2 }) } ! 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) } } } Going Loopy !86 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] * 2 }) } ! 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) } } } Going Loopy !87 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] * 2 }) } ! 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) } } } Going Loopy !88 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] * 2 }) } ! 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) } } } Going Loopy !89 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: p := []Value{ ValueOf(i) } for i := 0; i < 5; 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)) } } } Going Loopy !90 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: p := []Value{ ValueOf(i) } for i := 0; i < 5; 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)) } } } Going Loopy !91 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: p := []Value{ ValueOf(i) } for i := 0; i < 5; 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()) } } } Going Loopy !92 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: p := []Value{ ValueOf(i) } for i := 0; i < 5; 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()) } } } Going Loopy !93 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: p := []Value{ ValueOf(i) } for i := 0; i < 5; 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()) } } } Going Loopy !94 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: p := []Value{ ValueOf(i) } for i := 0; i < 5; 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()) } } } Going Loopy !95 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: p := []Value{ ValueOf(i) } for i := 0; i < 5; 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()) } } } Going Loopy !96 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: p := []Value{ ValueOf(i) } for i := 0; i < 5; 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()) } } } Going Loopy !97 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: p := []Value{ ValueOf(i) } for i := 0; i < 5; 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()) } } } Going Loopy !98 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: p := []Value{ ValueOf(i) } for i := 0; i < 5; 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()) } } } Going Loopy !99 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: p := []Value{ ValueOf(i) } for i := 0; i < 5; 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()) } } } Going Loopy !100 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: p := []Value{ ValueOf(i) } for i := 0; i < 5; 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()) } } } Going Loopy !101 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: p := []Value{ ValueOf(i) } for i := 0; i < 5; 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()) } } } Going Loopy !102 http://slides.games-with-brains.net/
    • user-defined type Going Loopy !103 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() { s := IterableSlice{ 0, 2, 4, 6, 8 } i := 0 s.Each(func(v interface{}) { Printf("%v: %vn", i, v) i++ }) } Going Loopy !104 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() { s := IterableSlice{ 0, 2, 4, 6, 8 } i := 0 s.Each(func(v interface{}) { Printf("%v: %vn", i, v) i++ }) } Going Loopy !105 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() { s := IterableSlice{ 0, 2, 4, 6, 8 } i := 0 s.Each(func(v interface{}) { Printf("%v: %vn", i, v) i++ }) } Going Loopy !106 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() { s := IterableSlice{ 0, 2, 4, 6, 8 } i := 0 s.Each(func(v interface{}) { Printf("%v: %vn", i, v) i++ }) } Going Loopy !107 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() { s := IterableSlice{ 0, 2, 4, 6, 8 } i := 0 s.Each(func(v interface{}) { Printf("%v: %vn", i, v) i++ }) } Going Loopy !108 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() { s := IterableSlice{ 0, 2, 4, 6, 8 } i := 0 s.Each(func(v interface{}) { Printf("%v: %vn", i, v) i++ }) } Going Loopy !109 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() { s := IterableSlice{ 0, 2, 4, 6, 8 } i := 0 s.Each(func(v interface{}) { Printf("%v: %vn", i, v) i++ }) } Going Loopy !110 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() { s := IterableSlice{ 0, 2, 4, 6, 8 } i := 0 s.Each(func(v interface{}) { Printf("%v: %vn", i, v) i++ }) } Going Loopy !111 http://slides.games-with-brains.net/
    • you now know go Going Loopy 112 http://slides.games-with-brains.net/
    • #golang Going Loopy 113 http://slides.games-with-brains.net/
    • http://golang.org/ Going Loopy 114 http://slides.games-with-brains.net/