Currently implementing a custom java.util.Iterator
with the usual deftype form like
(deftype MyIterator []
Iterator
(hasNext [this]
(my-custom-code))
(next [this]
(my-custom-code))
)
But I'd like to override the forEachRemaining
default method on Iterator
:
default void forEachRemaining(Consumer<? super E> action) {
Objects.requireNonNull(action);
while (hasNext())
action.accept(next());
}
... with a more performant/specialized implementation. Perhaps I would even want to implement the by-default unimplemented remove
:
default void remove() {
throw new UnsupportedOperationException("remove");
}
But deftype does not allow for overriding methods. Is this a fundamental limitation or just something that hasn't been done (probably because Clojure predates default methods in java 8)? Anyways as a language whose philosophy is to embrace the the host, this would come in highly useful for using/integrating with java interfaces.