Navigation Menu

Skip to content
This repository has been archived by the owner on Mar 22, 2021. It is now read-only.

Commit

Permalink
gofmt it
Browse files Browse the repository at this point in the history
  • Loading branch information
miekg committed Feb 10, 2012
1 parent 869eba3 commit 6704a3f
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions ex-beyond/src/map.go
@@ -1,32 +1,33 @@
package main

import "fmt"

/* define the empty interface as a type */
//* define the empty interface as a type
type e interface{}

func mult2(f e) e {
switch f.(type) {
case int:
return f.(int) * 2
case string:
return f.(string) + f.(string) + f.(string) + f.(string)
}
return f
switch f.(type) {
case int:
return f.(int) * 2
case string:
return f.(string) + f.(string) + f.(string) + f.(string)
}
return f
}

func Map(n []e, f func(e) e) []e {
m := make([]e, len(n))
for k, v := range n {
m[k] = f(v)
}
return m
m := make([]e, len(n))
for k, v := range n {
m[k] = f(v)
}
return m
}

func main() {
m := []e{1, 2, 3, 4}
s := []e{"a", "b", "c", "d"}
mf := Map(m, mult2)
sf := Map(s, mult2)
fmt.Printf("%v\n", mf)
fmt.Printf("%v\n", sf)
m := []e{1, 2, 3, 4}
s := []e{"a", "b", "c", "d"}
mf := Map(m, mult2)
sf := Map(s, mult2)
fmt.Printf("%v\n", mf)
fmt.Printf("%v\n", sf)
}

0 comments on commit 6704a3f

Please sign in to comment.