Iterators in Go — Bitfield Consulting
for _, v := range Items() {
... // do something with v
}
An iterator is just a function, but with a particular signature. For example
func iterateItems(yield func(Item) bool) bool {
:= []Item{1, 2, 3}
items for _, v := range items {
if !yield(v) {
return false
}
}
return true
}
No comments:
Post a Comment