Created
November 11, 2014 02:38
-
-
Save mrgriscom/3b564a23bd6ba0c43a5e to your computer and use it in GitHub Desktop.
the java singularity?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static <E> Iterable<Iterable<E>> chunker(final Iterator<E> stream, final long size) { | |
return new Iterable<Iterable<E>>() { | |
public Iterator<Iterable<E>> iterator() { | |
return new Iterator<Iterable<E>>() { | |
public boolean hasNext() { | |
return stream.hasNext(); | |
} | |
public Iterable<E> next() { | |
return new Iterable<E>() { | |
public Iterator<E> iterator() { | |
return new Iterator<E>() { | |
long count = 0; | |
public boolean hasNext() { | |
return stream.hasNext() && count < size; | |
} | |
public E next() { | |
count += 1; | |
return stream.next(); | |
} | |
public void remove() { | |
throw new UnsupportedOperationException(); | |
} | |
}; | |
} | |
}; | |
} | |
public void remove() { | |
throw new UnsupportedOperationException(); | |
} | |
}; | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment