![JAR search and dependency download from the Maven repository](/logo.png)
jio.TripleExp Maven / Gradle / Ivy
package jio;
import static java.util.Objects.requireNonNull;
import fun.tuple.Triple;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Predicate;
/**
* Represents an expression that is reduced to a triple. Their elements can be evaluated either in parallel or
* sequentially. In both cases, if one fails, the whole expression fails immediately.
*
* You can create TripleExp expressions using the 'seq' method to evaluate effects sequentially, or using the 'par'
* method to evaluate effects in parallel. If one effect fails, the entire expression fails.
*
* @param the type of the first computation
* @param the type of the second computation
* @param the type of the third computation
*/
public abstract sealed class TripleExp extends Exp> permits
TripleExpPar,
TripleExpSeq {
final IO _1;
final IO _2;
final IO _3;
TripleExp(final IO _1,
final IO _2,
final IO _3,
final Function, Throwable>> debugger
) {
super(debugger);
this._1 = _1;
this._2 = _2;
this._3 = _3;
}
/**
* create a tuple of three effects that will be evaluated sequentially. If an effect fails, the next ones are not
* evaluated and the whole expression fails.
*
* @param first the first effect
* @param second the second effect
* @param third the third effect
* @param the type of the first effect result
* @param the type of the second effect result
* @param the type of the third effect result
* @return a PairExp
*/
public static TripleExp seq(final IO first,
final IO second,
final IO third
) {
return new TripleExpSeq<>(requireNonNull(first),
requireNonNull(second),
requireNonNull(third),
null
);
}
/**
* Create a tuple of three effects that will be evaluated in paralell. If one fails, the whole expression fails
* immediately
*
* @param first the first effect
* @param second the second effect
* @param third the third effect
* @param type of the first effect result
* @param type of the second effect result
* @param type of the third effect result
* @return a pair expression evaluated in parallel
*/
public static TripleExp par(final IO first,
final IO second,
final IO third
) {
return new TripleExpPar<>(requireNonNull(first),
requireNonNull(second),
requireNonNull(third),
null
);
}
/**
* returns the first effect of the triple
*
* @return first effect of the triple
*/
public IO first() {
return _1;
}
/**
* returns the second effect of the triple
*
* @return second effect of the triple
*/
public IO second() {
return _2;
}
/**
* returns the third effect of the triple
*
* @return third effect of the triple
*/
public IO third() {
return _3;
}
@Override
public abstract TripleExp retryEach(final Predicate super Throwable> predicate,
final RetryPolicy policy
);
@Override
public TripleExp retryEach(final RetryPolicy policy) {
return retryEach(e -> true,
policy
);
}
@Override
public abstract TripleExp debugEach(final EventBuilder> messageBuilder
);
@Override
public abstract TripleExp debugEach(final String context);
}