code: public static <T, U> Collector<T, ?, Optional<T>> percentileBy(double percentile, Function<? super T, ? extends U> function, Comparator<? super U> comparator) {
          if (percentile < 0.0 || percentile > 1.0)
              throw new IllegalArgumentException("Percentile must be between 0.0 and 1.0");
  
          // At a later stage, we'll optimise this implementation in case that function is the identity function
          return Collector.of(
              () -> new ArrayList<Tuple2<T, U>>(),
              (l, v) -> l.add(tuple(v, function.apply(v))),
              (l1, l2) -> {
                  l1.addAll(l2);
                  return l1;
              },
              l -> {
                  int size = l.size();
  
                  if (size == 0)
                      return Optional.empty();
                  else if (size == 1)
                      return Optional.of(l.get(0).v1);
  
                  l.sort(Comparator.comparing(t -> t.v2, comparator));
  
                  if (percentile == 0.0)
                      return Optional.of(l.get(0).v1);
                  else if (percentile == 1.0)
                      return Optional.of(l.get(size - 1).v1);
  
                  // x.5 should be rounded down
                  return Optional.of(l.get((int) -Math.round(-(size * percentile + 0.5)) - 1).v1);
              }
          );
      }
docs: Get a {@link Collector} that calculates the derived <code>PERCENTILE_DISC(percentile)</code> function given a specific ordering.