private static Task <Result <T> > ContinuationFactory <T>(Task <T> sourceTask) => sourceTask .ContinueWith(task => task.Exception == null ? task.IsCanceled ? FailFactory.GenericCanceled <T>(task) : new Success <T>(task.Result) : FailFactory.GenericException <T>(task.Exception));
public static Task <Result> Bind(this Task <Result> sourceTask, Action effect) => sourceTask .ContinueWith(task => task.Exception == null ? task.IsCanceled ? FailFactory.ValuelessCanceled(task) : task.Result.Bind(effect) : FailFactory.ValuelessException(task.Exception));
public static Task <Result> Bind <T>(this Task <Result <T> > sourceTask, Func <T, Task> asyncEffect) => sourceTask .ContinueWith(task => task.Exception == null ? task.IsCanceled ? FailFactory.ValuelessCanceledTask(task) : task.Result.Bind(asyncEffect) : FailFactory.ValuelessExceptionTask(task.Exception)) .Unwrap();
public static Task <Result <T> > Bind <T>(this Task <Result> sourceTask, Func <T> factory) => sourceTask .ContinueWith(task => task.Exception == null ? task.IsCanceled ? FailFactory.GenericCanceled <T>(task) : task.Result.Bind(factory) : FailFactory.GenericException <T>(task.Exception) );
public static Task <Result <T> > ThenWrapAsResult <T>(this Task <T> sourceTask) => sourceTask .ContinueWith(task => task.Exception == null ? task.IsCanceled ? FailFactory.GenericCanceled <T>(task) : task.Result.AsSuccess() : FailFactory.GenericException <T>(task.Exception) );
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> Bind <T>(this Task <Result <T> > sourceTask, Action <T, CancellationToken> effect, CancellationToken cancellationToken) => sourceTask .ContinueWith(task => task.Exception == null ? task.IsCanceled ? FailFactory.ValuelessCanceled(task) : task.Result.Bind(effect, cancellationToken) : FailFactory.ValuelessException(task.Exception) );
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();
public static Task <Result> Bind(this Result result, Func <Task> asyncEffect) => result.Successful ? asyncEffect() .ContinueWith(task => task.Exception == null ? task.IsCanceled ? FailFactory.ValuelessCanceled(task) : Result.Success : FailFactory.ValuelessException(task.Exception)) : Task .FromResult(result);
public static Task <Result> Bind(this Result result, Func <CancellationToken, Task> asyncEffect, CancellationToken cancellationToken) => result.Successful ? asyncEffect(cancellationToken) // ReSharper disable once MethodSupportsCancellation .ContinueWith(task => task.Exception == null ? task.IsCanceled ? FailFactory.ValuelessCanceled(task) : Result.Success : FailFactory.ValuelessException(task.Exception)) : Task .FromResult(result);
public static Task <Result <TMapped> > Bind <T, TMapped>(this Result <T> result, Func <T, CancellationToken, Task <TMapped> > asyncMapper, CancellationToken cancellationToken) => result.Successful ? asyncMapper(result, cancellationToken) // ReSharper disable once MethodSupportsCancellation .ContinueWith(task => task.Exception == null ? task.IsCanceled ? FailFactory.GenericCanceled <TMapped>(task) : task.Result.AsSuccess() : FailFactory.GenericException <TMapped>(task.Exception)) : FailFactory.GenericExceptionTask <TMapped>(((Fail <T>)result).Exception);
public static Task <Result> Bind <T>(this Result <T> result, Func <CancellationToken, Task> asyncEffect, CancellationToken cancellationToken) => result.Successful ? asyncEffect(cancellationToken) .ThenWrapAsResult() : FailFactory.ValuelessExceptionTask(((Fail <T>)result).Exception);
public static Result <TMapped> Bind <T, TMapped>(this Result <T> result, Func <T, TMapped> mapper) => result.Successful ? Execute.Safely(((Success <T>)result).Value, mapper) : FailFactory.GenericException <TMapped>(((Fail <T>)result).Exception);
public static Result <TMapped> Bind <T, TMapped>(this Result <T> result, Func <T, CancellationToken, TMapped> mapper, CancellationToken cancellationToken = default) => result.Successful ? Execute.Safely(((Success <T>)result).Value, mapper, cancellationToken) : FailFactory.GenericException <TMapped>(((Fail <T>)result).Exception);
public static Task <Result <TMapped> > Bind <T, TMapped>(this Result <T> result, Func <T, Task <TMapped> > asyncMapper) => result.Successful ? asyncMapper(((Success <T>)result).Value) .ThenWrapAsResult() : FailFactory.GenericExceptionTask <TMapped>(((Fail <T>)result).Exception);
public static Task <Result> ThenWrapAsResult(this Task sourceTask) => sourceTask .ContinueWith(task => task.Exception ?? (task.IsCanceled ? FailFactory.ValuelessCanceled(task) : Result.Success) );
public static Task <Result> Bind <T>(this Result <T> result, Func <T, Task> asyncEffect) => result.Successful ? asyncEffect(((Success <T>)result).Value) .ThenWrapAsResult() : FailFactory.ValuelessExceptionTask(((Fail <T>)result).Exception);