code: public <R> Promise<T> chain(final Function<T, Promise<R>> res) {
          final Promise<T> self = this;
          return new Promise<>(resolver -> {
              self.then(t -> {
                  Promise<R> chained = res.apply(t);
                  chained.then(t2 -> resolver.result(t));
                  chained.failure(e -> resolver.error(e));
              });
              self.failure(e -> resolver.error(e));
          });
      }
docs: Chaining result to next promise and returning current value as result promise
  
  @param res chaining function
  @param <R> destination type
  @return promise