SEEqualElementsActionType ( @NotNull SearchEverywhereFoundElementInfo newItem, @NotNull List<? extends SearchEverywhereFoundElementInfo> alreadyFoundItems ) { return alreadyFoundItems.stream() .map(alreadyFoundItem -> { if (areEqual(newItem, alreadyFoundItem)) { return SearchEverywhereFoundElementInfo.COMPARATOR.compare(newItem, alreadyFoundItem) > 0 ? new SEEqualElementsActionType.Replace(alreadyFoundItem) : SEEqualElementsActionType.Skip.INSTANCE; } return SEEqualElementsActionType.DoNothing.INSTANCE; }) .reduce((foo, bar) -> foo.combine(bar)) .orElse(SEEqualElementsActionType.DoNothing.INSTANCE); }