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

jio.AllExpSeq Maven / Gradle / Ivy

The newest version!
package jio;

import static java.util.Objects.requireNonNull;

import java.util.List;
import java.util.Objects;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Predicate;
import jio.Result.Failure;
import jio.Result.Success;

final class AllExpSeq extends AllExp {

  public AllExpSeq(List> exps,
                   Function> debugger
                  ) {
    super(debugger,
          exps
         );
  }

  @Override
  public AllExp retryEach(final Predicate predicate,
                          final RetryPolicy policy
                         ) {
    requireNonNull(predicate);
    requireNonNull(policy);

    return new AllExpSeq(exps.stream()
                             .map(it -> it.retry(predicate,
                                                 policy
                                                ))
                             .toList(),
                         jfrPublisher
    );
  }

  @Override
  Result reduceExp() {
    return get(exps);
  }

  private Result get(List> exps) {
    var result = true;
    for (IO exp : exps) {
      try {
        if (result) {
          result = exp.call()
                      .getOutputOrThrow();
        } else {
          return new Success<>(false);
        }
      } catch (Exception e) {
        return new Failure<>(e);
      }
    }
    return new Success<>(result);

  }

  @Override
  public AllExp debugEach(final EventBuilder builder) {
    Objects.requireNonNull(builder);
    return new AllExpSeq(DebuggerHelper.debugConditions(exps,
                                                        builder
                                                       ),
                         getJFRPublisher(builder)
    );
  }

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

  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy