Iteration refactor

This merges iternext() and itervalid() into a single iternext() method returning a <yielded value, boolean> pair. It also introduces a iternext_impl() decorator which makes it easier to populate such pair.