apply(T t) throws E; } static <T, R> Function<T, R> checkedWrapper(ThrowingFun<T, R, Exception> throwingFun) { return t -> { try { return throwingFun.apply(t); } catch (Exception e) { throw new RuntimeException(e.getMessage()); } }; } int localStudentCount(List<String> studentIds, List<String> localSchools) { return studentIds.stream() .map(checkedWrapper(SchoolService::fetchStudentSchoolName)) .map(checkedWrapper(SchoolService::parseSchoolName)) .filter(localSchools::contains) .toList() .size(); }