Find again
Object findIf(Iterator iter, Predicate test)
{
while(iter.hasNext())
{
Object current = iter.next();
if(test.test(current))
return current;
}
return null;
}
Iterator i = ... some iterator ...
Predicate p = ... some test ...
Object o = Lib.findIf(i, p);
while(o != null)
{
...
o = Lib.findIf(i, p);
}
Also, that since we only advance as far as we need to, we can pass the iterator back in to find subsequent matches.
Which starts to look a bit like an iterator ... perhaps we could cast our find as an iterator as well?