FluentIterator implements ImmutableIterator<T> { public <K> FluentIterator<T> skipDuplicates(Function<T, K> key) { return fluent(Iterators.skipDuplicates(this, key)); } FluentIterator(Iterator<T> t); static FluentIterator<T> fluent(Iterator<T> t); @Override boolean hasNext(); @Override T next(); boolean weakEquals(Iterator<T> s, int n); @SuppressWarnings("unchecked") FluentIterator<T> filter(Predicate<? super T> p); boolean any(Predicate<? super T> p); boolean all(Predicate<? super T> p); @SuppressWarnings("unchecked") FluentIterator<T> concat(Iterator... ts); FluentIterator<T> peek(Consumer<? super T> cs); List<T> take(int n); List<T> takeAll(); FluentIterator<T> limit(int n); List<FluentIterator<T>> tee(int n); FluentIterator<Pair<T, S>> zip(Iterator<S> s, boolean weak); FluentIterator<List<T>> groupBy(Function<T, K> key); FluentIterator<List<T>> groupBy(); FluentIterator<T> skipDuplicates(Function<T, K> key); FluentIterator<T> skipDuplicates(); FluentIterator<T> keepFirst(Function<? super T, ? extends K> key); FluentIterator<T> keepLast(Function<? super T, ? extends K> key); FluentIterator<V> map(Function<T, V> f); FluentIterator<T> map(Iterator<T> t, BinaryOperator<T> f); T reduce(BinaryOperator<T> f); V reduce(BiFunction<V, T, V> f, V start);  }
@Test public void testSkipDuplicates() { FluentIterator<Integer> s = fluent(empty()); BiFunction<Integer, Integer, Integer> f = (a, b) -> a + b; int sum = s.skipDuplicates().reduce(f, 0); assertEquals(0, sum); s = fluent(repeat(17, 100)); BinaryOperator<Integer> acc = (a, b) -> a + b; sum = s.skipDuplicates().reduce(acc); assertEquals(17, sum); FluentIterator<Integer> r = fluent(repeat(17, 100)).concat(repeat(18, 100)); sum = r.skipDuplicates().reduce(acc); assertEquals(35, sum); r = fluent(repeat(7, 100)).concat(repeat(10, 100)); List<Integer> xs = r.skipDuplicates(x -> x % 3).takeAll(); assertEquals(1, xs.size()); assertEquals((Integer) 7, xs.get(0)); xs = fluent(of(2)).skipDuplicates().takeAll(); assertEquals(1, xs.size()); xs = fluent(of(2, 3)).skipDuplicates().takeAll(); assertEquals(2, xs.size()); }