ap<A, B> function
- Task<
B Function(A)> fTask
Applies the function inside a Task to the value inside another Task.
Given a Task containing a function from A
to B
(fTask
)
and another Task containing a value of type A
(m
),
this function returns a new Task that will eventually produce
a value of type B
by applying the function to the value.
Example:
Task<int Function(String)> funcTask = Task(() => Future.value((String s) => s.length));
Task<String> valueTask = Task(() => Future.value("Hello"));
Task<int> resultTask = ap(funcTask)(valueTask);
Implementation
Task<B> Function(Task<A> task) ap<A, B>(Task<B Function(A)> fTask) =>
(Task<A> m) => Task<B>(() async => (await fTask.task())(await m.task()));