@Override default <U> Tree<Tuple2<T, U>> zip(Iterable<U> that) { Objects.requireNonNull(that, "that is null"); if (isEmpty()) { return Empty.instance(); } else { return Zip.apply((Node<T>) this, that.iterator()); } }
@SuppressWarnings("unchecked") static <T, U> Tree<Tuple2<T, U>> apply(Node<T> node, java.util.Iterator<U> that) { if (!that.hasNext()) { return Empty.instance(); } else { final Tuple2<T, U> value = Tuple.of(node.getValue(), that.next()); final List<Node<Tuple2<T, U>>> children = (List<Node<Tuple2<T, U>>>) (Object) node.getChildren().map(child -> Zip.apply(child, that)).filter(Tree::isDefined); return new Node<>(value, children); } }