public static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
        final Map<Object, Boolean> seen = new ConcurrentHashMap<>();
        return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
    }
public static < T > Predicate < T > distinctByKey ( Function < ? super T , ? > keyExtractor ) { final Map < Object , Boolean > seen = new ConcurrentHashMap < > ( ) ; return t -> seen . putIfAbsent ( keyExtractor . apply ( t ) , Boolean . TRUE ) == null ; }
Taken from http://stackoverflow.com/a/27872852

@param keyExtractor The key extractor function
@param <T>          the generic type
@return a predicate for filtering