Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.*;
import java.util.function.BiFunction;

import java.util.stream.Stream;
import java.util.stream.Stream.Builder;

public class Main {
    public static <A, B, C> Stream<C> zip(Stream<A> as, Stream<B> bs, BiFunction<A, B, C> f) {
        Iterator<A> asIterator = as.iterator();
        Iterator<B> bsIterator = bs.iterator();

        Builder<C> builder = Stream.builder();

        while (asIterator.hasNext() && bsIterator.hasNext()) {
            builder.add(f.apply(asIterator.next(), bsIterator.next()));
        }

        return builder.build();
    }
}