void () { Processor<Runnable> tryCatch = (r) -> { try { r.run(); return true; } catch (NoSuchElementException e) { return false; } }; JBIterator<Integer> it = JBIterator.from(Arrays.asList(1, 2, 3, 4).iterator()); assertFalse(tryCatch.process(it::current)); assertTrue(it.hasNext()); assertFalse(tryCatch.process(it::current)); assertTrue(it.advance()); // advance->1 assertEquals(Integer.valueOf(1), it.current()); assertTrue(it.hasNext()); assertTrue(it.hasNext()); assertEquals(Integer.valueOf(2), it.next()); // advance->2 assertEquals(Integer.valueOf(2), it.current()); assertEquals(Integer.valueOf(2), it.current()); assertTrue(it.advance()); // advance->3 assertEquals(Integer.valueOf(4), it.next()); // advance->4 assertFalse(it.hasNext()); assertFalse(it.hasNext()); assertFalse(it.advance()); assertFalse(tryCatch.process(it::current)); assertFalse(tryCatch.process(it::next)); assertFalse(it.hasNext()); }