diff options
Diffstat (limited to 'core/object.go')
-rw-r--r-- | core/object.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/core/object.go b/core/object.go index 36b669e..d777f4a 100644 --- a/core/object.go +++ b/core/object.go @@ -139,6 +139,28 @@ func (iter *ObjectLookupIter) Next() (Object, error) { return obj, err } +// ForEach call the cb function for each object 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 *ObjectLookupIter) ForEach(cb func(Object) error) error { + for _, hash := range iter.series { + obj, err := iter.storage.Get(hash) + if err != nil { + return err + } + + if err := cb(obj); err != nil { + if err == ErrStop { + return nil + } + + return nil + } + } + + return nil +} + // Close releases any resources used by the iterator. func (iter *ObjectLookupIter) Close() { iter.pos = len(iter.series) @@ -173,6 +195,23 @@ func (iter *ObjectSliceIter) Next() (Object, error) { return obj, nil } +// ForEach call the cb function for each object 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 *ObjectSliceIter) ForEach(cb func(Object) error) error { + for _, o := range iter.series { + if err := cb(o); err != nil { + if err == ErrStop { + return nil + } + + return nil + } + } + + return nil +} + // Close releases any resources used by the iterator. func (iter *ObjectSliceIter) Close() { iter.pos = len(iter.series) |