aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/zwobble/couscous/util/ExtraIterables.java
blob: 9cdb0f04d700efb10772edb2b8bf1750acc4adfe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package org.zwobble.couscous.util;

import java.util.Iterator;

public class ExtraIterables {
    private ExtraIterables() {}

    public static <T, U> void forEach(Iterable<? extends T> first, Iterable<? extends U> second, Action2<T, U> action) {
        Iterator<? extends T> firstIterator = first.iterator();
        Iterator<? extends U> secondIterator = second.iterator();
        while (firstIterator.hasNext()) {
            action.run(firstIterator.next(), secondIterator.next());
        }
        if (secondIterator.hasNext()) {
            throw new RuntimeException("Iterables not of same length");
        }
    }
}