Exemplo n.º 1
0
    public static TryCase <A> Case <A>(this Try <A> ma)
    {
        if (ma == null)
        {
            return(FailCase <A> .New(Error.Bottom));
        }
        var res = ma.Try();

        return(res.IsSuccess
            ? SuccCase <A> .New(res.Value)
            : FailCase <A> .New(res.Exception));
    }
Exemplo n.º 2
0
    public static TryCase <A> Case <A>(this TryOption <A> ma)
    {
        if (ma == null)
        {
            return(FailCase <A> .New(Error.Bottom));
        }
        var res = ma.Try();

        return(res.IsSome
            ? SuccCase <A> .New(res.Value.Value)
            : res.IsNone
                ? NoneCase <A> .Default
                : FailCase <A> .New(res.Exception));
    }
Exemplo n.º 3
0
 public static async Task <TryCase <A> > Case <A>(this Task <A> ma)
 {
     if (ma == null)
     {
         return(FailCase <A> .New(Common.Error.Bottom));
     }
     try
     {
         return(SuccCase <A> .New(await ma));
     }
     catch (Exception ex)
     {
         return(FailCase <A> .New(ex));
     }
 }