code: public static <T, U> Collector<T, ?, Optional<Long>> rankBy(U value, Function<? super T, ? extends U> function, Comparator<? super U> comparator) {
          return Collector.of(
              () -> new long[] { -1L },
              (l, v) -> {
                  if (l[0] == -1L)
                      l[0] = 0L;
  
                  if (comparator.compare(value, function.apply(v)) > 0)
                      l[0] = l[0] + 1L;
              },
              (l1, l2) -> {
                  l1[0] = (l1[0] == -1 ? 0L : l1[0]) +
                          (l2[0] == -1 ? 0L : l2[0]);
  
                  return l1;
              },
              l -> l[0] == -1 ? Optional.empty() : Optional.of((long) l[0])
          );
      }
docs: Get a {@link Collector} that calculates the derived <code>RANK()</code> function given a specific ordering.