From 6cb67cdd8c1b4170147488d796e725a623f93884 Mon Sep 17 00:00:00 2001 From: Andrew Dunham Date: Tue, 14 Apr 2015 16:58:20 -0700 Subject: [PATCH] Add a helper function Err, similar to graph.Next --- graph/iterator.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/graph/iterator.go b/graph/iterator.go index 86d0fd9..f9edd52 100644 --- a/graph/iterator.go +++ b/graph/iterator.go @@ -177,6 +177,17 @@ func Next(it Iterator) bool { return false } +// Err is a convenience function that conditionally calls the Err method +// of an Iterator if it is a Nexter. If the Iterator is not a Nexter, Err +// returns nil. +func Err(it Iterator) error { + if n, ok := it.(Nexter); ok { + return n.Err() + } + glog.Errorln("Calling Err on an un-nextable iterator") + return nil +} + // Height is a convienence function to measure the height of an iterator tree. func Height(it Iterator, until Type) int { if it.Type() == until {