public static <R> Iterator<R> limit(final Iterator<R> iterator, final int limit) {
        return new Iterator<>() {
            private int iterated;

            @Override
            public boolean hasNext() {
                return iterated < limit && iterator.hasNext();
            }

            @Override
            public R next() {
                iterated++;
                return iterator.next();
            }

            @Override
            public void remove() {
                iterator.remove();
            }
        };
    }
@Test
    public void testUpToNElement_whenIteratorLimited() {
        Iterator<Integer> limitedIterator = IterableUtil.limit(numbers.iterator(), 2);

        assertEquals(Integer.valueOf(1), limitedIterator.next());
        assertEquals(Integer.valueOf(2), limitedIterator.next());
        assertFalse(limitedIterator.hasNext());
    }