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

com.teststeps.thekla4j.utils.vavr.TransformOption Maven / Gradle / Ivy

package com.teststeps.thekla4j.utils.vavr;

import io.vavr.Function1;
import io.vavr.control.Option;
import io.vavr.control.Try;

public class TransformOption {
  /**
   * transforming an Option{R} into an Try{R}
   *
   * @param errorMessage in case the Option is empty create a failing Try with this error message
   * @return Either{L,R}
   */
  public static  Function1, Try> toTry(String errorMessage) {
    return option -> option.isEmpty() ? Try.failure(new Throwable(errorMessage)) :
        Try.success(option.get());
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy