public static Outcome <IEnumerable <ResultType> > ThenForEach <T, ResultType>(this Outcome <IEnumerable <T> > @this, Func <ResultType> fn)
        {
            if ([email protected])
            {
                return(Outcome <IEnumerable <ResultType> > .Reject(@this.FailureOrThrow()));
            }

            return(Outcome.Of(() => @this.ResultOrDefault(Enumerable.Empty <T>()).Select(_ => fn())));
        }
        public static Outcome <T> Catch <T>(this Outcome <T> @this, Func <T> fn)
        {
            if (IsIgnorable(@this))
            {
                return(@this);
            }

            return(Outcome.Of(() => fn()));
        }
Beispiel #3
0
        public static Outcome <ResultType> Map <T, ResultType>(this Outcome <T> @this, Func <ResultType> fn)
        {
            if ([email protected])
            {
                return(Outcome <ResultType> .Reject(@this.FailureOrNull()));
            }

            return(Outcome.Of(fn));
        }
        public static Outcome <T> Catch <T>(this Outcome <T> @this, Func <Failure, T> fn)
        {
            if (IsIgnorable(@this))
            {
                return(@this);
            }

            return(Outcome.Of(() => fn(@this.FailureOrThrow())));
        }
        public static Outcome <ResultType> Then <T, ResultType>(this Outcome <T> @this, Func <T, ResultType> fn)
        {
            if ([email protected])
            {
                return(Outcome <ResultType> .Reject(@this.FailureOrNull()));
            }

            return(Outcome.Of(() => fn(@this.ResultOrDefault())));
        }
Beispiel #6
0
        public static Outcome <T> Catch <T>(this Outcome <T> @this, Filter filter, Func <T> fn)
        {
            if (!IsCatchable(@this, filter))
            {
                return(@this);
            }

            return(Outcome.Of(() => fn()));
        }
        /*
         * ***********************************************************************************
         * Async Operations
         * ***********************************************************************************
         */

        public static async Task <Outcome <T> > Catch <T>(this Task <Outcome <T> > @this, Func <Failure, T> fn)
        {
            var outcome = await @this.ConfigureAwait(false);

            if (IsIgnorable(outcome))
            {
                return(outcome);
            }

            return(Outcome.Of(() => fn(outcome.FailureOrNull())));
        }
Beispiel #8
0
        public static Task <Outcome <ReturnType> > Map <T, ReturnType>(this Outcome <T> outcome, Func <Task <ReturnType> > asyncFunc)
        {
            if (outcome.IsSuccessful)
            {
                return(Outcome.Of(asyncFunc));
            }

            return(Outcome <ReturnType>
                   .Reject(outcome.FailureOrNull())
                   .ForAsync());
        }
Beispiel #9
0
        /*
         * ***********************************************************************************
         * Async Operations
         * ***********************************************************************************
         */

        public static async Task <Outcome <T> > Catch <T>(this Task <Outcome <T> > @this, Filter filter, Func <Failure, T> fn)
        {
            var outcome = await @this;

            if (!IsCatchable(outcome, filter))
            {
                return(outcome);
            }

            return(Outcome.Of(() => fn(outcome.FailureOrNull())));
        }
        public static async Task <Outcome <ResultType> > Map <T, ResultType>(this Task <Outcome <T> > asyncPromise, Func <ResultType> func) //where ResultType: class
        {
            return(await Try(async() => {
                var outcome = await asyncPromise;
                if (outcome.IsSuccessful)
                {
                    return Outcome.Of(func);
                }

                return Outcome <ResultType> .Reject(outcome.FailureOrNull());
            }));
        }
Beispiel #11
0
        /// <summary>
        /// Applies the given function on all elements of the input enumerable and
        /// returns an enumerable of the results.
        /// </summary>
        /// <typeparam name="TResult">The return type of the generator function.</typeparam>
        /// <typeparam name="TParam">The element type of the input enumerable.</typeparam>
        /// <param name="parameters">The input enumerable.</param>
        /// <param name="generator">The function to be applied.</param>
        /// <returns>The enumerable of results.</returns>
        public static Outcome <IEnumerable <TResult> > MapAll <T, TResult>(
            this Outcome <IEnumerable <T> > @this,
            Func <T, TResult> fn)
        {
            if ([email protected])
            {
                return(Outcome <IEnumerable <TResult> >
                       .Reject(@this.FailureOrThrow()));
            }

            return(Outcome.Of(
                       () => @this
                       .ResultOrDefault(Enumerable.Empty <T>())
                       .Select(r => fn(r))
                       ));
        }