PyDetectedSdk (@NotNull String associatedName, @NotNull List<PyDetectedSdk> envs, @NotNull Function<PyDetectedSdk, String> envRootName) { return StreamEx .of(envs) .filter(sdk -> associatedName.equals(envRootName.apply(sdk))) .max( Comparator .comparing(PySdkExtKt::getGuessedLanguageLevel) .thenComparing(PyDetectedSdk::getHomePath) ) .orElse(null); }