public static Task <Result <T> > Bind <T>(this Task <Result> sourceTask, Func <CancellationToken, Task <T> > asyncFactory, CancellationToken cancellationToken) => sourceTask .ContinueWith(task => task.Exception == null ? task.IsCanceled ? FailFactory.GenericCanceledTask <T>(task) : task.Result.Bind(asyncFactory, cancellationToken) : FailFactory.GenericExceptionTask <T>(task.Exception)) .Unwrap();
public static Task <Result <TMapped> > Bind <T, TMapped>(this Task <Result <T> > sourceTask, Func <T, Task <TMapped> > asyncMapper) => sourceTask .ContinueWith(task => task.Exception == null ? task.IsCanceled ? FailFactory.GenericCanceledTask <TMapped>(task) : task.Result .Bind(asyncMapper) : FailFactory.GenericExceptionTask <TMapped>(task.Exception)) .Unwrap();