All Downloads are FREE. Search and download functionalities are using the official Maven repository.

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());
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy