/// <summary> /// By default, Some case is converted to 200 OK and None is 404. /// Optionally, provide functions to handle Some and None cases. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="option"></param> /// <returns></returns> public static Task <IActionResult> ToActionResult <T>(this OptionAsync <T> option, Func <T, IActionResult> some = null, Func <IActionResult> none = null) => option.Match(some ?? Ok, none ?? NotFound);
public OptionAsync <A> Append(OptionAsync <A> x, OptionAsync <A> y) => Plus(x, y);
public Func <Unit, Task <int> > Count(OptionAsync <A> ma) => async _ => await ma.IsSome ? 1 : 0;
public OptionAsync <A> Optional(A value) => OptionAsync <A> .Optional(value);
public OptionAsync <A> BindReturn(Unit _, OptionAsync <A> mb) => mb;
public Task <bool> EqualsAsync(OptionAsync <A> x, OptionAsync <A> y) => default(EqOptionAsync <EqDefault <A>, A>).EqualsAsync(x, y);
public OptionAsync <A> Some(A value) => isnull(value) ? throw new ArgumentNullException(nameof(value)) : OptionAsync <A> .Some(value);
public Task <bool> IsSome(OptionAsync <A> opt) => opt.IsSome;
public static OptionAsync <B> Apply <A, B>(this Func <A, B> fab, OptionAsync <A> fa) => ApplOptionAsync <A, B> .Inst.Apply(fab, fa);
public OptionAsync <A> ReturnAsync(Func <Unit, Task <A> > f) => OptionAsync <A> .SomeAsync(f(unit));
public Task <bool> IsNone(OptionAsync <A> opt) => opt.IsNone;
public OptionAsync <A> Plus(OptionAsync <A> a, OptionAsync <A> b) => default(MOptionAsync <A>).RunAsync(async __ => await a.IsSome.ConfigureAwait(false) ? a : b);
public Func <Unit, Task <S> > Fold <S>(OptionAsync <A> ma, S state, Func <S, A, S> f) => async _ =>
public MB Bind <MonadB, MB, B>(OptionAsync <A> ma, Func <A, MB> f) where MonadB : struct, MonadAsync <Unit, Unit, MB, B> => default(MonadB).RunAsync(async _ => (await ma.IsSome.ConfigureAwait(false)) ? f(await ma.Value.ConfigureAwait(false)) : default(MonadB).Fail(ValueIsNoneException.Default));
public static OptionAsync <A> Subtract <NUM, A>(this OptionAsync <A> x, OptionAsync <A> y) where NUM : struct, Num <A> => from a in x from b in y select subtract <NUM, A>(a, b);
public static OptionAsync <C> Apply <A, B, C>(this Func <A, B, C> fabc, OptionAsync <A> fa, OptionAsync <B> fb) => ApplOptionAsync <A, B, C> .Inst.Apply(curry(fabc), fa, fb);
public static OptionAsync <A> Divide <NUM, A>(this OptionAsync <A> x, OptionAsync <A> y) where NUM : struct, Num <A> => from a in x from b in y select divide <NUM, A>(a, b);
public static OptionAsync <Func <B, C> > Apply <A, B, C>(this OptionAsync <Func <A, B, C> > fabc, OptionAsync <A> fa) => from x in fabc from y in ApplOptionAsync <A, B, C> .Inst.Apply(curry(x), fa) select y;
public Task <int> GetHashCodeAsync(OptionAsync <A> x) => default(HashableOptionAsync <A>).GetHashCodeAsync(x);
public static OptionAsync <Func <B, C> > Apply <A, B, C>(this Func <A, Func <B, C> > fabc, OptionAsync <A> fa) => ApplOptionAsync <A, B, C> .Inst.Apply(fabc, fa);
public OptionAsync <A> SomeAsync(Task <A> taskA) => isnull(taskA) ? throw new ArgumentNullException(nameof(taskA)) : OptionAsync <A> .SomeAsync(taskA);
public static OptionAsync <B> Action <A, B>(this OptionAsync <A> fa, OptionAsync <B> fb) => ApplOptionAsync <A, B> .Inst.Action(fa, fb);
public OptionAsync <A> OptionalAsync(Task <A> taskA) => OptionAsync <A> .OptionalAsync(taskA);
public static async Task <A?> ToNullable <A>(this OptionAsync <A> ma) where A : struct => (await ma.IsNone) ? (A?)null : await ma.Value;
public MB BindAsync <MonadB, MB, B>(OptionAsync <A> ma, Func <A, Task <MB> > f) where MonadB : struct, MonadAsync <Unit, Unit, MB, B> => default(MonadB).RunAsync(async _ => (await ma.IsSome) ? await f(await ma.Value) : default(MonadB).Fail(ValueIsNoneException.Default));
/// <summary> /// Sum the bound value /// </summary> /// <remarks>This is a legacy method for backwards compatibility</remarks> /// <param name="a">Option of int</param> /// <returns>The bound value or 0 if None</returns> public static Task <int> Sum(this OptionAsync <int> a) => a.IfNone(0);
public Func <Unit, Task <S> > FoldBackAsync <S>(OptionAsync <A> ma, S state, Func <S, A, Task <S> > f) => FoldAsync(ma, state, f);
/// <summary> /// Sum the bound value /// </summary> /// <remarks>This is a legacy method for backwards compatibility</remarks> /// <param name="self">Option of A that is from the type-class NUM</param> /// <returns>The bound value or 0 if None</returns> public static Task <A> Sum <NUM, A>(this OptionAsync <A> self) where NUM : struct, Num <A> => sumAsync <NUM, MOptionAsync <A>, OptionAsync <A>, A>(self);
public OptionAsync <A> Plus(OptionAsync <A> a, OptionAsync <A> b) => default(MOptionAsync <A>).RunAsync(async __ => await a.IsSome ? a : b);
/// <summary> /// Some case is converted to Ok JsonResult. None case is 404. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="option"></param> /// <returns></returns> public static Task <IActionResult> ToActionResult <T>(this OptionAsync <T> option) => option.Match(Ok, NotFound);