map<A, B> function

Option<B> Function(Option<A> p1) map<A, B>(
  1. B f(
    1. A
    )
)

Transforms the value inside an Option using a given function.

The map function is used to apply a transformation to the value wrapped inside an Option. If the input Option is None, the result will also be None. If the input Option contains a value, the transformation function will be applied to that value, and the transformed value will be wrapped in a Some instance.

Example:

Option<int> someValue = Some(5);

var squared = map<int, int>((x) => x * x)(someValue);  // Should result in Some(25)

var noneInput = map<int, int>((x) => x + 5)(None());   // Should result in None

@param f A function that takes a value of type A and returns a value of type B. @return A function that takes an Option of type A and returns an Option of type B.

Implementation

Option<B> Function(Option<A> p1) map<A, B>(B Function(A) f) =>
    match<A, Option<B>>(() => None<B>(), (a) => Some<B>(f(a)));