public static Iterator<Resource> getIterator(Function<?, ?> function, Iterator<Resource> parentIterator) {
if (function instanceof ResourceToResourceFunction) {
ResourceToIteratorFunction wrappingFunction = new ResourceToIteratorWrapperFunction(
(ResourceToResourceFunction) function);
return new FunctionIterator(wrappingFunction, parentIterator);
} else if (function instanceof ResourceToIteratorFunction) {
return new FunctionIterator((ResourceToIteratorFunction) function, parentIterator);
} else if (function instanceof IteratorToIteratorFunction) {
return ((IteratorToIteratorFunction) function).apply(parentIterator);
} else {
throw new IllegalArgumentException("Don't know how to handle " + function.toString());
}