code: public static <T> Collector<T, ?, Integer> distinctCount(Function<? super T, ?> mapper) {
          final Collector<Object, ?, Set<Object>> downstream = Collectors.toSet();
  
          final Function<Set<Object>, Integer> finisher = new Function<Set<Object>, Integer>() {
              @Override
              public Integer apply(Set<Object> t) {
                  return t.size();
              }
          };
  
          return Collectors.collectingAndThen(Collectors.mapping(mapper, downstream), finisher);
      }
docs: It's copied from StreamEx: https://github.com/amaembo/streamex under Apache License v2 and may be modified.
  <br />
  
  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.