vertx.effect.mock.ValMock 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.mock;
import io.vertx.core.Future;
import vertx.effect.Val;
import vertx.effect.exp.Cons;
import java.util.Objects;
import java.util.function.IntFunction;
import java.util.function.Supplier;
public class ValMock implements Supplier> {
private int counter;
private final IntFunction getValue;
private final Val val;
public ValMock(final IntFunction getValue) {
this.getValue = Objects.requireNonNull(getValue);
this.val = Cons.of(() -> {
counter += 1;
return Future.succeededFuture(getValue.apply(counter));
}
);
}
@Override
public Val get() {
//danger zone, counter is mutable, we have to return a brand new instance
return new ValMock<>(getValue).val;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy