code: public static <T> Collector<T, ?, Integer> distinctCount(Function<? super T, ?> mapper) {
          return Collectors.collectingAndThen(Collectors.mapping(mapper, Collectors.toSet()), Set::size);
      }
docs: Returns a {@code Collector} which counts a number of distinct values the
  mapper function returns for the stream elements.
  
  <p>
  The operation performed by the returned collector is equivalent to
  {@code stream.map(mapper).distinct().count()}. This collector is mostly
  useful as a downstream collector.
  
  @param <T> the type of the input elements
  @param mapper a function which classifies input elements.
  @return a collector which counts a number of distinct classes the mapper
  function returns for the stream elements.