vertx.effect.exp.ParallelSeq Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vertx-effect Show documentation
Show all versions of vertx-effect Show documentation
When actors meet Functional Programming
package vertx.effect.exp;
import io.vertx.core.CompositeFuture;
import io.vertx.core.Future;
import vertx.effect.RetryPolicy;
import vertx.effect.Val;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.function.Supplier;
import static java.util.Objects.requireNonNull;
class ParallelSeq extends ListExp {
@SuppressWarnings("rawtypes")
protected static final ListExp EMPTY = new ParallelSeq<>(io.vavr.collection.List.empty());
ParallelSeq(final io.vavr.collection.List> seq) {
super(seq);
}
@Override
public Val> retry(final int attempts) {
if (attempts < 1)
return Cons.failure(new IllegalArgumentException(ATTEMPTS_LOWER_THAN_ONE_ERROR));
return new ParallelSeq<>(seq.map(it -> it.retry(attempts)));
}
@Override
public Val> retry(final int attempts,
final BiFunction> retryPolicy) {
if (attempts < 1)
return Cons.failure(new IllegalArgumentException(ATTEMPTS_LOWER_THAN_ONE_ERROR));
if (retryPolicy == null)
return Cons.failure(new NullPointerException("retryPolicy is null"));
return new ParallelSeq<>(seq.map(it -> it.retry(attempts,
retryPolicy
)));
}
@Override
public Val> retry(final Predicate predicate,
final int attempts) {
if (attempts < 1)
return Cons.failure(new IllegalArgumentException(ATTEMPTS_LOWER_THAN_ONE_ERROR));
if (predicate == null)
return Cons.failure(new NullPointerException("predicate is null"));
return new ParallelSeq<>(seq.map(it -> it.retry(predicate,
attempts
))
);
}
@Override
public Val> retry(final Predicate predicate,
final int attempts,
final RetryPolicy retryPolicy) {
if (attempts < 1)
return Cons.failure(new IllegalArgumentException(ATTEMPTS_LOWER_THAN_ONE_ERROR));
if (predicate == null)
return Cons.failure(new NullPointerException("predicate is null"));
return new ParallelSeq<>(seq.map(it -> it.retry(predicate,
attempts,
retryPolicy
)));
}
@Override
@SuppressWarnings({"unchecked", "rawtypes"})
public Future> get() {
java.util.List futures = seq.map(Supplier::get)
.toJavaList();
return CompositeFuture.all(futures)
.map(CompositeFuture::list);
}
@Override
public ListExp append(final Val extends O> exp) {
return new ParallelSeq<>(seq.append(requireNonNull(exp)));
}
@Override
public ListExp prepend(final Val extends O> exp) {
return new ParallelSeq<>(seq.prepend(requireNonNull(exp)));
}
@Override
public Val race() {
return Functions.race(seq);
}
@Override
public ListExp tail() {
return new ParallelSeq<>(seq.tail());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy