code: public static <T> Collector<T, ?, List<T>> head(int n) {
          if (n <= 0)
              return empty();
          return new CancellableCollectorImpl<>(ArrayList::new, (acc, t) -> {
              if (acc.size() < n)
                  acc.add(t);
          }, (acc1, acc2) -> {
              acc1.addAll(acc2.subList(0, Math.min(acc2.size(), n - acc1.size())));
              return acc1;
          }, Function.identity(), acc -> acc.size() >= n, ID_CHARACTERISTICS);
      }
docs: Returns a {@code Collector} which collects at most specified number of
  the first stream elements into the {@link List}.
  
  <p>
  This method returns a
  <a href="package-summary.html#ShortCircuitReduction">short-circuiting
  collector</a>.
  
  <p>
  There are no guarantees on the type, mutability, serializability, or
  thread-safety of the {@code List} returned.
  
  <p>
  The operation performed by the returned collector is equivalent to
  {@code stream.limit(n).collect(Collectors.toList())}. This collector is
  mostly useful as a downstream collector.
  
  @param <T> the type of the input elements
  @param n maximum number of stream elements to preserve
  @return a collector which returns a {@code List} containing the first n
  stream elements or less if the stream was shorter.