1private static <T> Predicate<T> distinctByKeys(Function<? super T, ?>... keyExtractors)
2{
3 final Map<List<?>, Boolean> seen = new ConcurrentHashMap<>();
4
5 return t ->
6 {
7 final List<?> keys = Arrays.stream(keyExtractors)
8 .map(ke -> ke.apply(t))
9 .collect(Collectors.toList());
10
11 return seen.putIfAbsent(keys, Boolean.TRUE) == null;
12 };
13}
14