示例#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);
 }
示例#2
0
 @SuppressWarnings("unchecked")
 @Override
 default <T1, T2, T3> Tuple3<Tree<T1>, Tree<T2>, Tree<T3>> unzip3(
     Function<? super T, Tuple3<? extends T1, ? extends T2, ? extends T3>> unzipper) {
   Objects.requireNonNull(unzipper, "unzipper is null");
   if (isEmpty()) {
     return Tuple.of(Empty.instance(), Empty.instance(), Empty.instance());
   } else {
     return (Tuple3<Tree<T1>, Tree<T2>, Tree<T3>>) (Object) Unzip.apply3((Node<T>) this, unzipper);
   }
 }