fromOption<A, B> function

Either<A, B> Function(Option<B> option) fromOption<A, B>(
  1. A leftValue(
      )
    )

    A function that takes a function that produces a leftValue and returns a function that converts an Option into an Either that is Left with the provided value if the option is None, and Right with the value from Some if the option is Some.

    Example usage:

    Option<int> someOption = Some(42);
    Option<int> noneOption = const None();
    
    var eitherFromOption = fromOption<String, int>(() => 'No value'); // returns a function
    Either<String, int> either1 = eitherFromOption(someOption);  // This will be Right(42)
    Either<String, int> either2 = eitherFromOption(noneOption);  // This will be Left('No value')
    

    @category lift

    Implementation

    Either<A, B> Function(Option<B> option) fromOption<A, B>(
            A Function() leftValue) =>
        (Option<B> option) =>
            option is Some<B> ? right<A, B>(option.value) : left<A, B>(leftValue());