Skip to content

Instantly share code, notes, and snippets.

@azihsoyn
Last active October 8, 2018 17:07
Show Gist options
  • Save azihsoyn/0706b65ad67b02321cd03896085c915f to your computer and use it in GitHub Desktop.
Save azihsoyn/0706b65ad67b02321cd03896085c915f to your computer and use it in GitHub Desktop.
collection by contract
type List(type T) []T
func (l *List(T)) Filter(func(T) bool) *List(T)
func (l *List(T)) Map(func(T) T) *List(T)
func main(){
var l List{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
l.Filter(func(i int) bool {
return i % 2 == 0
}).Map(func(i int) string{
return fmt.Sprintf("No. %d", i)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment