match<A, B> function

B Function(Option<A>) match<A, B>(
  1. B onNone(
      ),
    1. B onSome(
      1. A
      )
    )

    A pattern matching function for Option that provides branching based on the content of the Option.

    This function facilitates pattern matching on an Option<A>, executing one of the provided functions based on whether the Option is a Some or None. Both onSome and onNone functions have the same return type in this variation of the match function.

    Parameters:

    • onNone: A function that gets called if the Option is a None. It returns a value of type B.
    • onSome: A function that gets called if the Option is a Some. It accepts a value of type A and returns a value of type B.

    Returns:

    • A function that accepts an Option<A> and returns a value of type B.

    Example:

    final option = Some(5);
    final result = match<int, String>(
      () => "It's None",
      (value) => "Value is: $value"
    )(option);
    print(result);  // Outputs: Value is: 5
    

    Implementation

    B Function(Option<A>) match<A, B>(B Function() onNone, B Function(A) onSome) {
      return matchW<A, B, B>(onNone, onSome);
    }