Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

map multiple fields from java stream

private static <T> Predicate<T> distinctByKeys(Function<? super T, ?>... keyExtractors) 
{
  final Map<List<?>, Boolean> seen = new ConcurrentHashMap<>();
   
  return t -> 
  {
    final List<?> keys = Arrays.stream(keyExtractors)
                .map(ke -> ke.apply(t))
                .collect(Collectors.toList());
     
    return seen.putIfAbsent(keys, Boolean.TRUE) == null;
  };
}
Source by howtodoinjava.com #
 
PREVIOUS NEXT
Tagged: #map #multiple #fields #java #stream
ADD COMMENT
Topic
Name
4+3 =