I've written the following extension method on tasks
public static async Task<TOut> TaskMap<TIn,TOut>(this Task<TIn> task, Func<TIn,TOut> f)
{
TIn x = await task;
return f(x);
}
I'm hoping what this does is just create a new task like the original one which just applies f
after the original task completes.
That is, Task y = t.TaskMap(x => x)
should really be the same as Task y = t
, barring a quick object construction and function call. It shouldn't fundamentally change when the original task is executed.
My questions are:
- Is this function sensible and does what I intend?
- Does it already exist?
ContinueWith
– John Wu