// Path: src/main/java/streams/factories/ExecPullFactory.java
// public class ExecPullFactory extends PullFactory implements ExecStreamAlg<Id.t, Pull.t> {
// 
//     @Override
//     public <T> App<Id.t, Long> count(App<Pull.t, T> app) {
//         Pull<T> self = Pull.prj(app);
//         long temp = 0L;
//         while (self.hasNext()) {
//             temp++;
//         }
//         return Id.inj(new Id<>(temp));
//     }
// 
//     @Override
//     public <T> App<Id.t, T> reduce(T identity, BinaryOperator<T> accumulator, App<Pull.t, T> app) {
//         Pull<T> self = Pull.prj(app);
//         T state = identity;
//         while (self.hasNext()) {
//             state = accumulator.apply(state, self.next());
//         }
//         return Id.inj(new Id<>(state));
//     }
// }
// 
// Path: src/main/java/streams/factories/RefCell.java
// public class RefCell<T> {
//     public T value;
// 
//     public RefCell(T value) {
//         this.value = value;
//     }
// }
// 
// Path: src/main/java/streams/higher/Pull.java
// public interface Pull<T> extends App<Pull.t, T>, Iterator<T> {
// 
//     static <A> Pull<A> prj(App<Pull.t, A> app) {
//         return (Pull<A>) app;
//     }
// 
//     static class t {
// 
//     }
// }


import org.openjdk.jmh.annotations.*;
import streams.factories.ExecPullFactory;
import streams.factories.RefCell;
import streams.higher.Pull;
import java.util.stream.Stream;
package benchmarks;



@State(Scope.Thread)
@BenchmarkMode(Mode.AverageTime)
public class Benchmark_IteratorPipelines {

    // For map, count, operations
    private static final int N = Integer.getInteger("benchmark.N", 1000);

    private Long[] v;

    @Setup
    public void setUp() {
        v = Helper.fillArray(N);
    }

    // Java 8 Benchmarks (Pull)
    @Benchmark
    public Long count_iterate_Java8Streams() {
        RefCell<Long> acc = new RefCell<>(0L);

        Stream.of(v)
                .iterator().forEachRemaining(i -> acc.value++);

        return acc.value;
    }

    @Benchmark
    public Long filter_count_iterate_Java8Streams() {
        RefCell<Long> acc = new RefCell<>(0L);

        Stream.of(v)
                .filter(x -> x % 2L == 0L)
                .iterator().forEachRemaining(i -> acc.value++);

        return acc.value;
    }

    @Benchmark
    public Long filter_map_count_iterate_Java8Streams() {
// Path: src/main/java/streams/factories/ExecPullFactory.java
// public class ExecPullFactory extends PullFactory implements ExecStreamAlg<Id.t, Pull.t> {
// 
//     @Override
//     public <T> App<Id.t, Long> count(App<Pull.t, T> app) {
//         Pull<T> self = Pull.prj(app);
//         long temp = 0L;
//         while (self.hasNext()) {
//             temp++;
//         }
//         return Id.inj(new Id<>(temp));
//     }
// 
//     @Override
//     public <T> App<Id.t, T> reduce(T identity, BinaryOperator<T> accumulator, App<Pull.t, T> app) {
//         Pull<T> self = Pull.prj(app);
//         T state = identity;
//         while (self.hasNext()) {
//             state = accumulator.apply(state, self.next());
//         }
//         return Id.inj(new Id<>(state));
//     }
// }
// 
// Path: src/main/java/streams/factories/RefCell.java
// public class RefCell<T> {
//     public T value;
// 
//     public RefCell(T value) {
//         this.value = value;
//     }
// }
// 
// Path: src/main/java/streams/higher/Pull.java
// public interface Pull<T> extends App<Pull.t, T>, Iterator<T> {
// 
//     static <A> Pull<A> prj(App<Pull.t, A> app) {
//         return (Pull<A>) app;
//     }
// 
//     static class t {
// 
//     }
// }


// Path: src/main/java/benchmarks/Benchmark_IteratorPipelines.java
import org.openjdk.jmh.annotations.*;
import streams.factories.ExecPullFactory;
import streams.factories.RefCell;
import streams.higher.Pull;
import java.util.stream.Stream;

package benchmarks;



@State(Scope.Thread)
@BenchmarkMode(Mode.AverageTime)
public class Benchmark_IteratorPipelines {

    // For map, count, operations
    private static final int N = Integer.getInteger("benchmark.N", 1000);

    private Long[] v;

    @Setup
    public void setUp() {
        v = Helper.fillArray(N);
    }

    // Java 8 Benchmarks (Pull)
    @Benchmark
    public Long count_iterate_Java8Streams() {
        RefCell<Long> acc = new RefCell<>(0L);

        Stream.of(v)
                .iterator().forEachRemaining(i -> acc.value++);

        return acc.value;
    }

    @Benchmark
    public Long filter_count_iterate_Java8Streams() {
        RefCell<Long> acc = new RefCell<>(0L);

        Stream.of(v)
                .filter(x -> x % 2L == 0L)
                .iterator().forEachRemaining(i -> acc.value++);

        return acc.value;
    }

    @Benchmark
    public Long filter_map_count_iterate_Java8Streams() {
        RefCell<Long> acc = new RefCell<>(0L);