aboutsummaryrefslogtreecommitdiffstats
path: root/core/reference.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-08-15 23:09:33 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-08-15 23:09:33 +0200
commit6b9a59be60de5b66aee14e9160ace80734008eca (patch)
treec302776360b0fd4f774f67f177870fda478b4258 /core/reference.go
parented2e3b299e03e4bfd4c37bf5232e9fde05c0600d (diff)
downloadgo-git-6b9a59be60de5b66aee14e9160ace80734008eca.tar.gz
core: *Iter.ForEach method
Diffstat (limited to 'core/reference.go')
-rw-r--r--core/reference.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/core/reference.go b/core/reference.go
index 89852da..bde3ff4 100644
--- a/core/reference.go
+++ b/core/reference.go
@@ -178,6 +178,23 @@ func (iter *ReferenceSliceIter) Next() (*Reference, error) {
return obj, nil
}
+// ForEach call the cb function for each reference contained on this iter until
+// an error happends or the end of the iter is reached. If ErrStop is sent
+// the iteration is stop but no error is returned
+func (iter *ReferenceSliceIter) ForEach(cb func(*Reference) error) error {
+ for _, r := range iter.series {
+ if err := cb(r); err != nil {
+ if err == ErrStop {
+ return nil
+ }
+
+ return nil
+ }
+ }
+
+ return nil
+}
+
// Close releases any resources used by the iterator.
func (iter *ReferenceSliceIter) Close() {
iter.pos = len(iter.series)