github.com/l3x/learn-fp-go@v0.0.0-20171228022418-7639825d0b71/4-purely-functional/ch09-functor-monoid/05_int_functor/src/functor/ints.go (about) 1 package functor 2 3 import ( 4 "fmt" 5 ) 6 7 type IntFunctor interface { 8 Map(f func(int) int) IntFunctor 9 } 10 11 type intBox struct { 12 ints []int 13 } 14 15 func (box intBox) Map(f func(int) int) IntFunctor { 16 for i, el := range box.ints { 17 box.ints[i] = f(el) 18 } 19 return box 20 } 21 22 func Functor(ints []int) IntFunctor { 23 return intBox{ints: ints} 24 } 25 26 func (box intBox) String() string { 27 return fmt.Sprintf("%+v", box.ints) 28 }