boolean (final T t) { ProgressManager.checkCanceled(); // in case of exception do not mark the element as processed, we couldn't recover otherwise M m = myMapper.fun(t); if (myProcessedElements.contains(m)) return true; boolean result = myConsumer.process(t); myProcessedElements.add(m); return result; }