ap<A, B> function

Option<B> Function(Option<A>) ap<A, B>(
  1. Option<B Function(A)> fOpt
)

Applies a function wrapped in an Option to a value also wrapped in an Option.

Given an Option of a function, and an Option of a value, it will return an Option of the result. If either the function or the value is None, the result will also be None.

Example:

Option<int Function(int)> someFunction = Some((int x) => x * 2);
Option<int> someValue = Some(10);

var result = ap(someFunction)(someValue);  // Should result in Some(20)

Option<int Function(int)> noFunction = None();

var resultWithNoneFunction = ap(noFunction)(someValue);  // Should result in None

@param fOpt An Option containing a function of type B Function(A). @return A function that takes an Option of type A and returns an Option of type B.

Implementation

Option<B> Function(Option<A>) ap<A, B>(Option<B Function(A)> fOpt) =>
    (Option<A> m) => flatMap<B Function(A), B>((f) => map<A, B>(f)(m))(fOpt);