Пример #1
0
        public static Try <B> Map <T, B>(this Try <T> tryValue, Func <T, B> mapper)
        {
            var failure = tryValue as Failure <T>;

            return(failure == null?
                   Try.From(mapper(tryValue.Value)) :
                       new Failure <B>(failure.Exception));
        }
Пример #2
0
        public static Try <B> Recover <T, B>(this Try <T> tryValue, Func <Exception, B> recovery) where B : T
        {
            if (tryValue.IsSuccess)
            {
                return(tryValue as Try <B>);
            }

            try
            {
                var failure = tryValue as Failure <T>;

                return(Try.From(recovery(failure.Exception)));
            }
            catch (Exception ex)
            {
                return(new Failure <B>(ex));
            }
        }
Пример #3
0
 public static Try <V> SelectMany <T, U, V>(this Try <T> tryValue, Func <T, Try <U> > selector, Func <T, U, V> resultSelector)
 {
     return(tryValue.SelectMany(x => selector(x).SelectMany(y => Try.From(resultSelector(x, y)))));
 }