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

jio.PairExpSeq Maven / Gradle / Ivy

The newest version!
package jio;

import static java.util.Objects.requireNonNull;

import fun.tuple.Pair;
import java.util.Objects;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Predicate;
import jio.Result.Failure;

final class PairExpSeq extends PairExp {

  public PairExpSeq(final IO _1,
                    final IO _2,
                    final Function, Throwable>> debugger
                   ) {
    super(debugger,
          _1,
          _2);
  }

  @Override
  public PairExp retryEach(final Predicate predicate,
                                          final RetryPolicy policy
                                         ) {
    requireNonNull(predicate);
    requireNonNull(policy);
    return new PairExpSeq<>(_1.retry(predicate,
                                     policy
                                    ),
                            _2.retry(predicate,
                                     policy
                                    ),
                            jfrPublisher
    );
  }

  @Override
  Result> reduceExp() {
    try {
      var first = _1.call()
                    .getOutputOrThrow();
      var second = _2.call()
                     .getOutputOrThrow();
      return new Result.Success<>(Pair.of(first,
                                          second
                                         ));
    } catch (Exception e) {
      return new Failure<>(e);
    }
  }

  @Override
  public PairExp debugEach(final EventBuilder> eventBuilder) {
    Objects.requireNonNull(eventBuilder);
    return new PairExpSeq<>(DebuggerHelper.debugIO(_1,
                                                   String.format("%s[1]",
                                                                 eventBuilder.exp
                                                                ),
                                                   eventBuilder.context
                                                  ),
                            DebuggerHelper.debugIO(_2,
                                                   String.format("%s[2]",
                                                                 eventBuilder.exp
                                                                ),
                                                   eventBuilder.context

                                                  ),
                            getJFRPublisher(eventBuilder)
    );
  }

  @Override
  public PairExp debugEach(final String context) {
    return this.debugEach(EventBuilder.of(this.getClass()
                                              .getSimpleName(),
                                          context)
                         );

  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy