public static Fallible <TResult> ReplaceBy <TSource, TResult>( this Fallible <TSource> @this, TResult value) { /* T4: NotNull(@this) */ return(@this.Select(_ => value)); }
public static Fallible <IEnumerable <TSource> > Repeat <TSource>( Fallible <TSource> source, int count) { /* T4: NotNull(source) */ Require.Range(count >= 0, nameof(count)); return(source.Select(val => Enumerable.Repeat(val, count))); }
/// <seealso cref="Apply{TSource, TResult}(Fallible{Func{TSource, TResult}}, Fallible{TSource})" /> public static Fallible <TResult> Gather <TSource, TResult>( this Fallible <TSource> @this, Fallible <Func <TSource, TResult> > applicative) { /* T4: NotNull(@this) */ /* T4: NotNull(applicative) */ return(applicative.Bind(func => @this.Select(func))); }
// Select() with automatic resource management. public static Fallible <TResult> Using <TSource, TResult>( this Fallible <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); } })); }
/// <seealso cref="Fallible.Lift{T1, T2, TResult}"/> public static Fallible <TResult> ZipWith <T1, T2, TResult>( this Fallible <T1> @this, Fallible <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)))); }