public static Either <TResult, TRight> ReplaceBy <TSource, TResult, TRight>( this Either <TSource, TRight> @this, TResult value) { Require.NotNull(@this, nameof(@this)); return(@this.Select(_ => value)); }
public static Either <IEnumerable <TSource>, TRight> Repeat <TSource, TRight>( Either <TSource, TRight> source, int count) { Require.NotNull(source, nameof(source)); Require.Range(count >= 0, nameof(count)); return(source.Select(val => Enumerable.Repeat(val, count))); }
/// <seealso cref="Apply{TSource, TResult, TRight}(Either{Func{TSource, TResult}, TRight}, Either{TSource, TRight})" /> public static Either <TResult, TRight> Gather <TSource, TResult, TRight>( this Either <TSource, TRight> @this, Either <Func <TSource, TResult>, TRight> applicative) { Require.NotNull(@this, nameof(@this)); Require.NotNull(applicative, nameof(applicative)); return(applicative.Bind(func => @this.Select(func))); }
// Select() with automatic resource management. public static Either <TResult, TRight> Using <TSource, TResult, TRight>( this Either <TSource, TRight> @this, Func <TSource, TResult> selector) where TSource : IDisposable { Require.NotNull(@this, nameof(@this)); Require.NotNull(selector, nameof(selector)); return(@this.Select(val => { using (val) { return selector(val); } })); }
/// <seealso cref="Either.Lift{T1, T2, TResult, TRight}"/> public static Either <TResult, TRight> ZipWith <T1, T2, TResult, TRight>( this Either <T1, TRight> @this, Either <T2, TRight> second, Func <T1, T2, TResult> zipper) { Require.NotNull(@this, nameof(@this)); Require.NotNull(second, nameof(second)); Require.NotNull(zipper, nameof(zipper)); return(@this.Bind( arg1 => second.Select( arg2 => zipper(arg1, arg2)))); }