All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jnape.palatable.lambda.iterators.ZippingIterator Maven / Gradle / Ivy

There is a newer version: 5.5.0
Show newest version
package com.jnape.palatable.lambda.iterators;

import java.util.Iterator;
import java.util.function.BiFunction;

public class ZippingIterator extends ImmutableIterator {
    private final BiFunction zipper;
    private final Iterator                                   asIterator;
    private final Iterator                                   bsIterator;

    public ZippingIterator(BiFunction zipper, Iterator asIterator,
                           Iterator bsIterator) {
        this.asIterator = asIterator;
        this.bsIterator = bsIterator;
        this.zipper = zipper;
    }

    @Override
    public boolean hasNext() {
        return asIterator.hasNext() && bsIterator.hasNext();
    }

    @Override
    public C next() {
        return zipper.apply(asIterator.next(), bsIterator.next());
    }
}