
io.github.olib963.javatest.fixtures.Try Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javatest-fixtures Show documentation
Show all versions of javatest-fixtures Show documentation
Functionality to manage the lifecycle of fixtures required for tests
The newest version!
package io.github.olib963.javatest.fixtures;
import io.github.olib963.javatest.CheckedSupplier;
import io.github.olib963.javatest.fixtures.internal.Failure;
import io.github.olib963.javatest.fixtures.internal.Success;
import java.util.function.Function;
public interface Try {
Try mapError(Function f);
Try map(Function f);
Try flatMap(Function> f);
A recoverWith(Function f);
static Try Try(CheckedSupplier function) {
try {
return new Success<>(function.get());
} catch (Exception e) {
return new Failure<>(e);
}
}
static Try Try(CheckedConsumer function, T value) {
try {
function.accept(value);
return Success();
} catch (Exception e) {
return new Failure<>(e);
}
}
static Try Success() {
return new Success<>(null);
}
static Try Success(T value) {
return new Success<>(value);
}
static Try Failure(String reason) {
return new Failure<>(new Exception(reason));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy