@FunctionalInterface
public interface Consumer5<T1, T2, T3, T4, T5> extends ConsumerN {
  void accept(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5);
} public class Tuple5<T1, T2, T3, T4, T5> extends Tuple<Tuple5<T1, T2, T3, T4, T5>> {
  private final T1 t1;
  private final T2 t2;
  private final T3 t3;
  private final T4 t4;
  private final T5 t5;

  /**
   * Construct using values for the three types
   *
   * @param t1 the value of the first type
   * @param t2 the value of the second type
   * @param t3 the value of the third type
   * @param t4 the value of the fourth type
   * @param t5 the value of the fifth type
   */
  public Tuple5(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) {
    this.t1 = t1;
    this.t2 = t2;
    this.t3 = t3;
    this.t4 = t4;
    this.t5 = t5;
  }

  /**
   * Construct from a <i>completed</i> future
   *
   * @param compositeFuture a composite future that should contain three values of types that are assignable to this types generic parameters
   */
  public Tuple5(CompositeFuture compositeFuture) {
    assert (compositeFuture.succeeded());
    this.t1 = compositeFuture.result(0);
    this.t2 = compositeFuture.result(1);
    this.t3 = compositeFuture.result(2);
    this.t4 = compositeFuture.result(3);
    this.t5 = compositeFuture.result(4);
  }

  /**
   * Retrieve the first value
   *
   * @return the value of the first type
   */
  public T1 getT1() {
    return t1;
  }

  /**
   * Retrieve the second value
   *
   * @return the value of the second type
   */
  public T2 getT2() {
    return t2;
  }

  /**
   * Retrieve the third value
   *
   * @return the value of the third type
   */
  public T3 getT3() {
    return t3;
  }

  /**
   * Retrieve the fourth value
   *
   * @return the value for the fourth type
   */
  public T4 getT4() {
    return t4;
  }

  /**
   * Retrieve the fourth value
   *
   * @return the value for the fifth type
   */
  public T5 getT5() {
    return t5;
  }

  /**
   * Calls a {@link Consumer5} function with the five values of this tuple. Any exceptions are propagated up the stack.
   *
   * @param consumer The consumer function, that will be called with five values from this tuple.
   */
  public void accept(Consumer5<T1, T2, T3, T4, T5> consumer) {
    consumer.accept(t1, t2, t3, t4, t5);
  }

  /**
   * Calls a {@link Function5} function with the five values of the tuple and returns the result of that function.
   * Any exceptions are propagated up the stack.
   *
   * @param function the function, that will be called with five values from this tuple and returns a result of type {@link R}
   * @param <R>      The type of the result returned from <code>#function</code>
   * @return The result from calling the function
   */
  public <R> R apply(Function5<T1, T2, T3, T4, T5, R> function) {
    return function.apply(t1, t2, t3, t4, t5);
  }


  /**
   * Implements deep equality of this object
   *
   * @param o right hand sideof the equality
   * @return true iff <code>this</code>is equal to <code>o</code>
   */
  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    Tuple5<?, ?, ?, ?, ?> tuple5 = (Tuple5<?, ?, ?, ?, ?>) o;

    if (t1 != null ? !t1.equals(tuple5.t1) : tuple5.t1 != null) return false;
    if (t2 != null ? !t2.equals(tuple5.t2) : tuple5.t2 != null) return false;
    if (t3 != null ? !t3.equals(tuple5.t3) : tuple5.t3 != null) return false;
    if (t4 != null ? !t4.equals(tuple5.t4) : tuple5.t4 != null) return false;
    return t5 != null ? t5.equals(tuple5.t5) : tuple5.t5 == null;

  }

  /**
   * Implements deep hashcode of this object
   *
   * @return hashcode
   */
  @Override
  public int hashCode() {
    int result = t1 != null ? t1.hashCode() : 0;
    result = 31 * result + (t2 != null ? t2.hashCode() : 0);
    result = 31 * result + (t3 != null ? t3.hashCode() : 0);
    result = 31 * result + (t4 != null ? t4.hashCode() : 0);
    result = 31 * result + (t5 != null ? t5.hashCode() : 0);
    return result;
  }
} @FunctionalInterface
public interface Consumer2<T1, T2> extends ConsumerN {
  void accept(T1 t1, T2 t2);
} @FunctionalInterface
public interface Consumer3<T1, T2, T3> extends ConsumerN {
  void accept(T1 t1, T2 t2, T3 t3);
} @FunctionalInterface
public interface Consumer4<T1, T2, T3, T4> extends ConsumerN {
  void accept(T1 t1, T2 t2, T3 t3, T4 t4);
} public class Tuple2<T1, T2> extends Tuple<Tuple2<T1, T2>> {
  private final T1 t1;
  private final T2 t2;

  /**
   * Construct using values for the two types
   * @param t1 the value of the first type
   * @param t2 the value of the second type
   */
  public Tuple2(T1 t1, T2 t2) {
    this.t1 = t1;
    this.t2 = t2;
  }

  /**
   * Construct from a <i>completed</i> future
   * @param compositeFuture a composite future that should contain two values of types that are assignable to this types generic parameters
   */
  public Tuple2(CompositeFuture compositeFuture) {
    assert(compositeFuture.succeeded());
    this.t1 = compositeFuture.result(0);
    this.t2 = compositeFuture.result(1);
  }

  /**
   * Retrieve the first value
   * @return the value of the first type
   */
  public T1 getT1() {
    return t1;
  }

  /**
   * Retrieve the second value
   * @return the value of the second type
   */
  public T2 getT2() {
    return t2;
  }

  /**
   * Calls a {@link Consumer2} function with the two values of this tuple. Any exceptions are propagated up the stack.
   * @param consumer The consumer function, that will be called with two values from this tuple.
   */
  public void accept(Consumer2<T1, T2> consumer) {
    consumer.accept(t1, t2);
  }

  /**
   * Calls a {@link Function2} function with the two values of the tuple and returns the result of that function.
   * Any exceptions are propagated up the stack.
   * @param function the function, that will be called with the two values from this tuple and returns a result of type {@link R}
   * @param <R> The type of the result returned from <code>#function</code>
   * @return The result from calling the function
   */
  public <R> R apply(Function2<T1, T2, R> function) {
    return function.apply(t1, t2);
  }

  /**
   * Implements deep equality of this object
   * @param o right hand sideof the equality
   * @return true iff <code>this</code>is equal to <code>o</code>
   */
  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    Tuple2<?, ?> tuple2 = (Tuple2<?, ?>) o;

    if (t1 != null ? !t1.equals(tuple2.t1) : tuple2.t1 != null) return false;
    return t2 != null ? t2.equals(tuple2.t2) : tuple2.t2 == null;

  }

  /**
   * Implements deep hashcode of this object
   * @return hashcode
   */
  @Override
  public int hashCode() {
    int result = t1 != null ? t1.hashCode() : 0;
    result = 31 * result + (t2 != null ? t2.hashCode() : 0);
    return result;
  }
} public class Tuple3<T1, T2, T3> extends Tuple<Tuple3<T1, T2, T3>> {
  private final T1 t1;
  private final T2 t2;
  private final T3 t3;

  /**
   * Construct using values for the three types
   * @param t1 the value of the first type
   * @param t2 the value of the second type
   * @param t3 the value of the third type
   */
  public Tuple3(T1 t1, T2 t2, T3 t3) {
    this.t1 = t1;
    this.t2 = t2;
    this.t3 = t3;
  }

  /**
   * Construct from a <i>completed</i> future
   * @param compositeFuture a composite future that should contain three values of types that are assignable to this types generic parameters
   */
  public Tuple3(CompositeFuture compositeFuture) {
    assert(compositeFuture.succeeded());
    this.t1 = compositeFuture.result(0);
    this.t2 = compositeFuture.result(1);
    this.t3 = compositeFuture.result(2);
  }

  /**
   * Retrieve the first value
   * @return the value of the first type
   */
  public T1 getT1() {
    return t1;
  }

  /**
   * Retrieve the second value
   * @return the value of the second type
   */
  public T2 getT2() {
    return t2;
  }

  /**
   * Retrieve the third value
   * @return the value of the third type
   */
  public T3 getT3() {
    return t3;
  }

  /**
   * Calls a {@link Consumer3} function with three values of this tuple. Any exceptions are propagated up the stack.
   * @param consumer The consumer function, that will be called with three values from this tuple.
   */
  public void accept(Consumer3<T1, T2, T3> consumer) {
    consumer.accept(t1, t2, t3);
  }

  /**
   * Calls a {@link Function3} function with the three values of the tuple and returns the result of that function.
   * Any exceptions are propagated up the stack.
   * @param function the function, that will be called with three values from this tuple and returns a result of type {@link R}
   * @param <R> The type of the result returned from <code>#function</code>
   * @return The result from calling the function
   */
  public <R> R apply(Function3<T1, T2, T3, R> function) {
    return function.apply(t1, t2, t3);
  }

  /**
   * Implements deep equality of this object
   * @param o right hand sideof the equality
   * @return true iff <code>this</code>is equal to <code>o</code>
   */
  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    Tuple3<?, ?, ?> tuple3 = (Tuple3<?, ?, ?>) o;

    if (t1 != null ? !t1.equals(tuple3.t1) : tuple3.t1 != null) return false;
    if (t2 != null ? !t2.equals(tuple3.t2) : tuple3.t2 != null) return false;
    return t3 != null ? t3.equals(tuple3.t3) : tuple3.t3 == null;

  }

  /**
   * Implements deep hashcode of this object
   * @return hashcode
   */
  @Override
  public int hashCode() {
    int result = t1 != null ? t1.hashCode() : 0;
    result = 31 * result + (t2 != null ? t2.hashCode() : 0);
    result = 31 * result + (t3 != null ? t3.hashCode() : 0);
    return result;
  }
} public class Tuple4<T1, T2, T3, T4> extends Tuple<Tuple4<T1, T2, T3, T4>> {
  private final T1 t1;
  private final T2 t2;
  private final T3 t3;
  private final T4 t4;

  /**
   * Construct using values for the three types
   *
   * @param t1 the value of the first type
   * @param t2 the value of the second type
   * @param t3 the value of the third type
   * @param t4 the value of the fourth type
   */
  public Tuple4(T1 t1, T2 t2, T3 t3, T4 t4) {
    this.t1 = t1;
    this.t2 = t2;
    this.t3 = t3;
    this.t4 = t4;
  }

  /**
   * Construct from a <i>completed</i> future
   *
   * @param compositeFuture a composite future that should contain three values of types that are assignable to this types generic parameters
   */
  public Tuple4(CompositeFuture compositeFuture) {
    assert (compositeFuture.succeeded());
    this.t1 = compositeFuture.result(0);
    this.t2 = compositeFuture.result(1);
    this.t3 = compositeFuture.result(2);
    this.t4 = compositeFuture.result(3);
  }

  /**
   * Retrieve the first value
   *
   * @return the value of the first type
   */
  public T1 getT1() {
    return t1;
  }

  /**
   * Retrieve the second value
   *
   * @return the value of the second type
   */
  public T2 getT2() {
    return t2;
  }

  /**
   * Retrieve the third value
   *
   * @return the value of the third type
   */
  public T3 getT3() {
    return t3;
  }

  /**
   * Retrieve the fourth value
   *
   * @return the value for the fourth type
   */
  public T4 getT4() {
    return t4;
  }

  /**
   * Calls a {@link Consumer4} function with the four values of this tuple. Any exceptions are propagated up the stack.
   *
   * @param consumer The consumer function, that will be called with four values from this tuple.
   */
  public void accept(Consumer4<T1, T2, T3, T4> consumer) {
    consumer.accept(t1, t2, t3, t4);
  }

  /**
   * Calls a {@link Function4} function with the four values of the tuple and returns the result of that function.
   * Any exceptions are propagated up the stack.
   *
   * @param function the function, that will be called with four values from this tuple and returns a result of type {@link R}
   * @param <R>      The type of the result returned from <code>#function</code>
   * @return The result from calling the function
   */
  public <R> R apply(Function4<T1, T2, T3, T4, R> function) {
    return function.apply(t1, t2, t3, t4);
  }


  /**
   * Implements deep equality of this object
   *
   * @param o right hand sideof the equality
   * @return true iff <code>this</code>is equal to <code>o</code>
   */
  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    Tuple4<?, ?, ?, ?> tuple4 = (Tuple4<?, ?, ?, ?>) o;

    if (t1 != null ? !t1.equals(tuple4.t1) : tuple4.t1 != null) return false;
    if (t2 != null ? !t2.equals(tuple4.t2) : tuple4.t2 != null) return false;
    if (t3 != null ? !t3.equals(tuple4.t3) : tuple4.t3 != null) return false;
    return t4 != null ? t4.equals(tuple4.t4) : tuple4.t4 == null;
  }

  /**
   * Implements deep hashcode of this object
   *
   * @return hashcode
   */
  @Override
  public int hashCode() {
    int result = t1 != null ? t1.hashCode() : 0;
    result = 31 * result + (t2 != null ? t2.hashCode() : 0);
    result = 31 * result + (t3 != null ? t3.hashCode() : 0);
    result = 31 * result + (t4 != null ? t4.hashCode() : 0);
    return result;
  }

} public interface Futures<T> extends Future<T> {
  <R> Futures<R> then(FutureProcessor<T, R> processor);

  static <T> Futures<T> when(Future<T> future) {
    return FuturesImpl.when(future);
  }

  static <T1, T2> Futures<Tuple2<T1, T2>> when(Future<T1> f1,
                                               Future<T2> f2) {
    return FuturesImpl.when(Tuple.tuple(f1, f2));
  }

  static <T1, T2, T3> Futures<Tuple3<T1, T2, T3>> when(Future<T1> f1,
                                                       Future<T2> f2,
                                                       Future<T3> f3) {
    return FuturesImpl.when(Tuple.tuple(f1, f2, f3));
  }

  static <T1, T2, T3, T4> Futures<Tuple4<T1, T2, T3, T4>> when(Future<T1> f1,
                                                               Future<T2> f2,
                                                               Future<T3> f3,
                                                               Future<T4> f4) {
    return FuturesImpl.when(Tuple.tuple(f1, f2, f3, f4));
  }

  static <T1, T2, T3, T4, T5> Futures<Tuple5<T1, T2, T3, T4, T5>> when(Future<T1> f1,
                                                                       Future<T2> f2,
                                                                       Future<T3> f3,
                                                                       Future<T4> f4,
                                                                       Future<T5> f5) {
    return FuturesImpl.when(Tuple.tuple(f1, f2, f3, f4, f5));
  }
} static <T> Handler<AsyncResult<T>> failure(Consumer<Throwable> consumer) {
  return result -> {
    if (result.failed()) {
      consumer.accept(result.cause());
    }
  };
} static <T> SuccessFilter<T> success(Consumer<T> consumer) {
  return result -> {
    if (result.succeeded()) {
      consumer.accept(result.result());
    }
  };
}
import io.dazraf.vertx.consumer.Consumer5;
import io.dazraf.vertx.tuple.Tuple5;
import org.slf4j.Logger;
import java.util.function.Consumer;
import io.dazraf.vertx.consumer.Consumer2;
import io.dazraf.vertx.consumer.Consumer3;
import io.dazraf.vertx.consumer.Consumer4;
import io.dazraf.vertx.tuple.Tuple2;
import io.dazraf.vertx.tuple.Tuple3;
import io.dazraf.vertx.tuple.Tuple4;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.dazraf.vertx.futures.Futures;
import static io.dazraf.vertx.futures.filters.FailureFilter.failure;
import static io.dazraf.vertx.futures.filters.SuccessFilter.success;
import static org.slf4j.LoggerFactory.getLogger;
package io.dazraf.vertx.futures.processors;





/**
 * This interface is a {@link FutureProcessor} that executes a function
 * given a state change in a {@link Futures} chain.
 *
 * No result is collected from the called function.
 * The type of the {@link Futures} chain does not alter.
 * An exception raised by the called function will cause the {@link Futures} chain to fail with the respective cause.
 */
public interface RunProcessor<T> extends FutureProcessor<T, T> {

  Logger LOG = getLogger(RunProcessor.class);

  /**
   * Observe the state of the chain. Any exceptions from the consumer will cause the chain to fail.
   * @param consumer
   * @param <T>
   * @return
   */
  static <T> RunProcessor<T> runOnResponse(Handler<AsyncResult<T>> consumer) {
    return future -> {
      Future<T> result = Future.future();
      try {
        consumer.handle(future);
        result.completer().handle(future);
      } catch (Throwable error) {
        LOG.error("consumer function failed", error);
        result.fail(error);
      }
      return result;
    };
  }

  static <T> RunProcessor<T> run(Runnable runnable) {
    return runOnResponse(success(runnable));
  }

  static <T> RunProcessor<T> run(Consumer<T> consumer) {
    return runOnResponse(success(consumer));
  }

  static <T1, T2> RunProcessor<Tuple2<T1, T2>> run(Consumer2<T1, T2> consumer) {
    return runOnResponse(success(consumer));
  }

  static <T1, T2, T3> RunProcessor<Tuple3<T1, T2, T3>> run(Consumer3<T1, T2, T3> consumer) {
    return runOnResponse(success(consumer));
  }

  static <T1, T2, T3, T4> RunProcessor<Tuple4<T1, T2, T3, T4>> run(Consumer4<T1, T2, T3, T4> consumer) {