com.teststeps.thekla4j.utils.vavr.TransformTry Maven / Gradle / Ivy
package com.teststeps.thekla4j.utils.vavr;
import io.vavr.Function1;
import io.vavr.control.Either;
import io.vavr.control.Try;
public class TransformTry {
/**
* transforming a Try{R} into an Either{L,R}
*
* @param toErrorFunction Either{L,R}
* @return Either{L,R}
*/
public static Function1, Either> toEither(Function1 toErrorFunction) {
return tryObj -> tryObj.isFailure() ? Either.left(toErrorFunction.apply(tryObj.getCause())) :
Either.right(tryObj.get());
}
}