All Downloads are FREE. Search and download functionalities are using the official Maven repository.

me.hltj.vertx.future.CompositeFutureTuple9 Maven / Gradle / Ivy

There is a newer version: 1.1.2
Show newest version
/*
 * vertx-future-utils - Convenient Utilities for Vert.x Future
 * https://github.com/hltj/vertx-future-utils
 *
 * Copyright (C) 2020  JiaYanwei  https://hltj.me
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This code is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see .
 *
 * Please contact me (jiaywe#at#gmail.com, replace the '#at#' with 'at')
 * if you need additional information or have any questions.
 */
package me.hltj.vertx.future;

import io.vertx.core.CompositeFuture;
import io.vertx.core.Future;
import lombok.ToString;
import me.hltj.vertx.function.*;

import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Supplier;

import static me.hltj.vertx.FutureUtils.joinWrap;

/**
 * The composite {@link Future} tuple warps a {@link CompositeFuture} and a {@link FutureTuple9}.
 * 

* Not only retains the type parameters of the original {@code Future}s, * but also provide many convenient operations as a complement to {@code CompositeFuture}. * * @param the type parameter of the 1st {@code Future} * @param the type parameter of the 2nd {@code Future} * @param the type parameter of the 3rd {@code Future} * @param the type parameter of the 4th {@code Future} * @param the type parameter of the 5th {@code Future} * @param the type parameter of the 6th {@code Future} * @param the type parameter of the 7th {@code Future} * @param the type parameter of the 8th {@code Future} * @param the type parameter of the 9th {@code Future} */ @ToString(includeFieldNames = false) final public class CompositeFutureTuple9 extends CompositeFutureWrapper { private final FutureTuple9 tuple9; private CompositeFutureTuple9(CompositeFuture composite, FutureTuple9 tuple9) { super(composite); this.tuple9 = tuple9; } /** * Create a {@link CompositeFutureTuple9} based on a {@link CompositeFuture} and a {@link FutureTuple9}. * * @param the type parameter of the 1st {@code Future} * @param the type parameter of the 2nd {@code Future} * @param the type parameter of the 3rd {@code Future} * @param the type parameter of the 4th {@code Future} * @param the type parameter of the 5th {@code Future} * @param the type parameter of the 6th {@code Future} * @param the type parameter of the 7th {@code Future} * @param the type parameter of the 8th {@code Future} * @param the type parameter of the 9th {@code Future} * @param tuple9 the {@code FutureTuple9} * @param compose the {@code CompositeFuture} * @return the {@code CompositeFutureTuple9} */ public static CompositeFutureTuple9 of( FutureTuple9 tuple9, CompositeFuture compose ) { return new CompositeFutureTuple9<>(compose, tuple9); } /** * Return the original {@link FutureTuple9}. */ public FutureTuple9 tuple() { return tuple9; } /** * Run side-effect code likes {@link CompositeFutureWrapper#use(Consumer)}, but the {@code consumer10} takes the * original 9 {@link Future}s as additional parameters. *

* It likes {@link CompositeFutureTuple2#use(Consumer3)} but with 9-arity. */ public void use( Consumer10, Future, Future, Future, Future, Future, Future, Future, Future> consumer10 ) { consumer10.accept( composite, tuple9.get_0(), tuple9.get_1(), tuple9.get_2(), tuple9.get_3(), tuple9.get_4(), tuple9.get_5(), tuple9.get_6(), tuple9.get_7(), tuple9.get_8() ); } /** * Map the original {@link CompositeFuture} and the original 9 {@link Future}s. *

* It likes {@link CompositeFutureTuple2#with(Function3)} but with 9-arity. */ public R with( Function10, Future, Future, Future, Future, Future, Future, Future, Future, R> function10 ) { return function10.apply( composite, tuple9.get_0(), tuple9.get_1(), tuple9.get_2(), tuple9.get_3(), tuple9.get_4(), tuple9.get_5(), tuple9.get_6(), tuple9.get_7(), tuple9.get_8() ); } /** * Alias for {@link #through(Function9)}. */ public Future mapAnyway( Function9, Future, Future, Future, Future, Future, Future, Future, Future, R> function9 ) { return through(function9); } /** * Map a function that takes the original 9 {@link Future}s on complete no matter whether succeeded or failed. *

* It likes {@link CompositeFutureTuple2#through(BiFunction)} but with 9-arity. */ public Future through( Function9, Future, Future, Future, Future, Future, Future, Future, Future, R> function9 ) { return joinThrough(function9.andThen(Future::succeededFuture)); } /** * Alias for {@link #joinThrough(Function9)}. */ public Future flatMapAnyway( Function9, Future, Future, Future, Future, Future, Future, Future, Future, Future> function9 ) { return joinThrough(function9); } /** * Map a function that takes the original 9 {@link Future}s on complete no matter whether succeeded or failed, * and join (also known as {@code flatten}) the result before return. * *

* It likes {@link CompositeFutureTuple2#joinThrough(BiFunction)} but with 9-arity. */ public Future joinThrough( Function9, Future, Future, Future, Future, Future, Future, Future, Future, Future> function9 ) { Supplier> supplier = () -> function9.apply( tuple9.get_0(), tuple9.get_1(), tuple9.get_2(), tuple9.get_3(), tuple9.get_4(), tuple9.get_5(), tuple9.get_6(), tuple9.get_7(), tuple9.get_8() ); return composite.compose(_x -> joinWrap(supplier), _t -> joinWrap(supplier)); } /** * Alias for {@link CompositeFutureTuple9#applift(Function9)}. */ public Future mapTyped(Function9 function9) { return applift(function9); } /** * Apply a function that accept all results of the original {@link Future}s on success, and return * a {@link Future}. *

* It likes {@link CompositeFutureTuple2#applift(BiFunction)} but with 9-arity. */ public Future applift(Function9 function9) { return composite.map(future -> function9.apply( composite.resultAt(0), composite.resultAt(1), composite.resultAt(2), composite.resultAt(3), composite.resultAt(4), composite.resultAt(5), composite.resultAt(6), composite.resultAt(7), composite.resultAt(8) )); } /** * Alias for {@link CompositeFutureTuple9#joinApplift(Function9)}. */ public Future flatMapTyped(Function9> function9) { return joinApplift(function9); } /** * Apply a function that accept all results of the original {@link Future}s on success, and return * a {@link Future}, where the function itself return a {@link Future}. *

* It likes {@link CompositeFutureTuple2#joinApplift(BiFunction)} but with 9-arity. */ public Future joinApplift(Function9> function9) { return composite.flatMap(future -> function9.apply( composite.resultAt(0), composite.resultAt(1), composite.resultAt(2), composite.resultAt(3), composite.resultAt(4), composite.resultAt(5), composite.resultAt(6), composite.resultAt(7), composite.resultAt(8) )); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy