Ejemplo n.º 1
0
 public static Outcome <TResult> ReplaceBy <TSource, TResult>(
     this Outcome <TSource> @this,
     TResult value)
 {
     /* T4: NotNull(@this) */
     return(@this.Select(_ => value));
 }
Ejemplo n.º 2
0
 public static Outcome <IEnumerable <TSource> > Repeat <TSource>(
     Outcome <TSource> source,
     int count)
 {
     /* T4: NotNull(source) */
     Require.Range(count >= 0, nameof(count));
     return(source.Select(val => Enumerable.Repeat(val, count)));
 }
Ejemplo n.º 3
0
 /// <seealso cref="Apply{TSource, TResult}(Outcome{Func{TSource, TResult}}, Outcome{TSource})" />
 public static Outcome <TResult> Gather <TSource, TResult>(
     this Outcome <TSource> @this,
     Outcome <Func <TSource, TResult> > applicative)
 {
     /* T4: NotNull(@this) */
     /* T4: NotNull(applicative) */
     return(applicative.Bind(func => @this.Select(func)));
 }
Ejemplo n.º 4
0
 // Select() with automatic resource management.
 public static Outcome <TResult> Using <TSource, TResult>(
     this Outcome <TSource> @this,
     Func <TSource, TResult> selector)
     where TSource : IDisposable
 {
     /* T4: NotNull(@this) */
     Require.NotNull(selector, nameof(selector));
     return(@this.Select(val => { using (val) { return selector(val); } }));
 }
Ejemplo n.º 5
0
        /// <seealso cref="Outcome.Lift{T1, T2, TResult}"/>
        public static Outcome <TResult> ZipWith <T1, T2, TResult>(
            this Outcome <T1> @this,
            Outcome <T2> second,
            Func <T1, T2, TResult> zipper)
        {
            /* T4: NotNull(@this) */
            /* T4: NotNull(second) */
            Require.NotNull(zipper, nameof(zipper));

            return(@this.Bind(
                       arg1 => second.Select(
                           arg2 => zipper(arg1, arg2))));
        }