/** * This function groups an iterator. * consecutive elements which are equal form a group. * The result is an Iterator of List of objects. * Example: x x x y y z produces ((x x x) (y y) (z)) * * @return the grouped iterator */ public FluentIterator<List<T>> groupBy() { return fluent(Iterators.groupBy(this, x -> x)); }
/** * This function groups an iterator by a key function: * consecutive elements with the same key value form a group. * The result is an Iterator of Lists of objects * Example: 4 7 10 5 8 11 3, key(x) = x%3 produces ((4 7 10) (5 8 11) (3)) * * @param key the key function controlling the grouping * @param <K> any type * @return the grouped iterator */ public <K> FluentIterator<List<T>> groupBy(Function<T, K> key) { return fluent(Iterators.groupBy(this, key)); }