// Path: src/main/java/net/kimleo/rec/v2/stream/MergeIterator.java
// public class MergeIterator<T> implements Iterator<T> {
// 
//     private final Iterator<T> first;
//     private final Iterator<T> second;
//     private T next1;
//     private T next2;
// 
//     private final Comparator<T> comparator;
// 
//     public MergeIterator(Iterator<T> first, Iterator<T> second, Comparator<T> comparator) {
//         this.first = first;
//         this.second = second;
//         next1 = first.hasNext() ? first.next() : null;
//         next2 = second.hasNext() ? second.next() : null;
//         this.comparator = comparator;
//     }
// 
//     @Override
//     public T next() {
// 
//         if(!hasNext()) {
//             return null;
//         }
// 
//         boolean useStream1 = (next1 != null && next2 == null)  ||
//                 (next1 != null && comparator.compare(next1, next2) <= 0);
// 
//         if(useStream1) {
//             T returnObject = next1;
//             next1 = first.hasNext() ? first.next() : null;
//             return returnObject;
//         }
//         else {
//             T returnObject = next2;
//             next2 = second.hasNext() ? second.next() : null;
//             return returnObject;
//         }
//    }
// 
//     @Override
//     public boolean hasNext() {
//         return next1 != null || next2 != null;
//     }
// }
// 
// Path: src/main/java/net/kimleo/rec/v2/stream/adapter/IteratingSpliteratorAdapter.java
// public class IteratingSpliteratorAdapter<T> extends Spliterators.AbstractSpliterator<T> {
// 
//     private final Iterator<T> iterator;
// 
//     public IteratingSpliteratorAdapter(Iterator<T> iterator) {
//         super(Long.MAX_VALUE, 0);
//         this.iterator = iterator;
//     }
// 
//     @Override
//     public boolean tryAdvance(Consumer<? super T> action) {
//         if (iterator.hasNext()) {
//             action.accept(iterator.next());
//             return true;
//         }
//         return false;
//     }
// }


import net.kimleo.rec.v2.stream.MergeIterator;
import net.kimleo.rec.v2.stream.adapter.IteratingSpliteratorAdapter;
import java.util.Comparator;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
package net.kimleo.rec.v2.utils;



public class Streams {
    public static <T extends Comparable<T>> Stream<T> merge(Stream<T> first,
                                                            Stream<T> second) {
// Path: src/main/java/net/kimleo/rec/v2/stream/MergeIterator.java
// public class MergeIterator<T> implements Iterator<T> {
// 
//     private final Iterator<T> first;
//     private final Iterator<T> second;
//     private T next1;
//     private T next2;
// 
//     private final Comparator<T> comparator;
// 
//     public MergeIterator(Iterator<T> first, Iterator<T> second, Comparator<T> comparator) {
//         this.first = first;
//         this.second = second;
//         next1 = first.hasNext() ? first.next() : null;
//         next2 = second.hasNext() ? second.next() : null;
//         this.comparator = comparator;
//     }
// 
//     @Override
//     public T next() {
// 
//         if(!hasNext()) {
//             return null;
//         }
// 
//         boolean useStream1 = (next1 != null && next2 == null)  ||
//                 (next1 != null && comparator.compare(next1, next2) <= 0);
// 
//         if(useStream1) {
//             T returnObject = next1;
//             next1 = first.hasNext() ? first.next() : null;
//             return returnObject;
//         }
//         else {
//             T returnObject = next2;
//             next2 = second.hasNext() ? second.next() : null;
//             return returnObject;
//         }
//    }
// 
//     @Override
//     public boolean hasNext() {
//         return next1 != null || next2 != null;
//     }
// }
// 
// Path: src/main/java/net/kimleo/rec/v2/stream/adapter/IteratingSpliteratorAdapter.java
// public class IteratingSpliteratorAdapter<T> extends Spliterators.AbstractSpliterator<T> {
// 
//     private final Iterator<T> iterator;
// 
//     public IteratingSpliteratorAdapter(Iterator<T> iterator) {
//         super(Long.MAX_VALUE, 0);
//         this.iterator = iterator;
//     }
// 
//     @Override
//     public boolean tryAdvance(Consumer<? super T> action) {
//         if (iterator.hasNext()) {
//             action.accept(iterator.next());
//             return true;
//         }
//         return false;
//     }
// }


// Path: src/main/java/net/kimleo/rec/v2/utils/Streams.java
import net.kimleo.rec.v2.stream.MergeIterator;
import net.kimleo.rec.v2.stream.adapter.IteratingSpliteratorAdapter;
import java.util.Comparator;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

package net.kimleo.rec.v2.utils;



public class Streams {
    public static <T extends Comparable<T>> Stream<T> merge(Stream<T> first,
                                                            Stream<T> second) {
        MergeIterator<T> iterator = new MergeIterator<>(