Exemplo n.º 1
0
 static <T, T1, T2> Tuple2<Node<T1>, Node<T2>> apply(
     Node<T> node, Function<? super T, Tuple2<? extends T1, ? extends T2>> unzipper) {
   final Tuple2<? extends T1, ? extends T2> value = unzipper.apply(node.getValue());
   final List<Tuple2<Node<T1>, Node<T2>>> children =
       node.getChildren().map(child -> Unzip.apply(child, unzipper));
   final Node<T1> node1 = new Node<>(value._1, children.map(t -> t._1));
   final Node<T2> node2 = new Node<>(value._2, children.map(t -> t._2));
   return Tuple.of(node1, node2);
 }
Exemplo n.º 2
0
 @SuppressWarnings("unchecked")
 @Override
 default <T1, T2> Tuple2<Tree<T1>, Tree<T2>> unzip(
     Function<? super T, Tuple2<? extends T1, ? extends T2>> unzipper) {
   Objects.requireNonNull(unzipper, "unzipper is null");
   if (isEmpty()) {
     return Tuple.of(Empty.instance(), Empty.instance());
   } else {
     return (Tuple2<Tree<T1>, Tree<T2>>) (Object) Unzip.apply((Node<T>) this, unzipper);
   }
 }