Created
July 9, 2022 12:08
-
-
Save krisraich/06db4eab1de1d4c9954d57c547be5405 to your computer and use it in GitHub Desktop.
add processing to java iterator
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
public static <I,O> Iterable<O> iteratorInterceptor(final Iterable<I> iterable, final Function<I, O> processor) { | |
return () -> { | |
final Iterator<I> iterator = iterable.iterator(); | |
return new Iterator<>() { | |
@Override | |
public boolean hasNext() { return iterator.hasNext(); } | |
@Override | |
public O next() { return processor.apply(iterator.next()); } | |
}; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment