Iterable<LookupElement> (MultiMap<CompletionSorterImpl, LookupElement> inputBySorter) { if (inputBySorter.isEmpty()) return Collections.emptyList(); List<Map.Entry<CompletionSorterImpl, Classifier<LookupElement>>> entries = new ArrayList<>(myClassifiers.entrySet()); return EntryStream.of(entries.iterator()) .mapKeyValue((sorter, classifier) -> classifier.classify(inputBySorter.get(sorter), createContext())) .flatMap(iterable -> StreamEx.of(iterable.iterator())) .toList(); // need to collect, as the resulting Iterable can be iterated several times }