Skip to content

Instantly share code, notes, and snippets.

@zacker330
Created January 24, 2018 08:35
Show Gist options
  • Save zacker330/c22f2960556f88b5c150b6d9e177a316 to your computer and use it in GitHub Desktop.
Save zacker330/c22f2960556f88b5c150b6d9e177a316 to your computer and use it in GitHub Desktop.
public static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
Set<Object> seen = ConcurrentHashMap.newKeySet();
return t -> seen.add(keyExtractor.apply(t));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment