code: public static <T> Stream<List<T>> aggregate(Stream<T> source, BiPredicate<T, T> predicate) {
          return StreamSupport.stream(new AggregatingSpliterator<>(source.spliterator(),
              (a, e) -> a.isEmpty() || predicate.test(a.get(a.size() - 1), e)), false)
                  .onClose(source::close);
      }
docs: Aggregates items from source stream into list of items while supplied predicate is true when evaluated on previous and current item.
  Can by seen as streaming alternative to Collectors.groupingBy when source stream is sorted by key.
  @param source - source stream
  @param predicate - predicate specifying boundary between groups of items
  @param <T> The type over which the stream streams.
  @return Stream of List&lt;T&gt; aggregated according to predicate