Beispiel #1
0
 public static MonadZero <TResult> ReplaceBy <TSource, TResult>(
     this MonadZero <TSource> @this,
     TResult value)
 {
     Require.NotNull(@this, nameof(@this));
     return(@this.Select(_ => value));
 }
Beispiel #2
0
 /// <seealso cref="Apply{TSource, TResult}(MonadZero{Func{TSource, TResult}}, MonadZero{TSource})" />
 public static MonadZero <TResult> Gather <TSource, TResult>(
     this MonadZero <TSource> @this,
     MonadZero <Func <TSource, TResult> > applicative)
 {
     Require.NotNull(@this, nameof(@this));
     Require.NotNull(applicative, nameof(applicative));
     return(applicative.Bind(func => @this.Select(func)));
 }
Beispiel #3
0
 // Select() with automatic resource management.
 public static MonadZero <TResult> Using <TSource, TResult>(
     this MonadZero <TSource> @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); } }));
 }
Beispiel #4
0
        private static Func <TKey, MonadZero <TInner> > GetKeyLookup <TInner, TKey>(
            MonadZero <TInner> inner,
            Func <TInner, TKey> innerKeySelector,
            IEqualityComparer <TKey> comparer)
        {
            Debug.Assert(inner != null);
            Debug.Assert(innerKeySelector != null);

            return(outerKey =>
                   inner.Select(innerKeySelector)
                   .Where(innerKey => (comparer ?? EqualityComparer <TKey> .Default).Equals(innerKey, outerKey))
                   .ContinueWith(inner));
        }
Beispiel #5
0
        /// <seealso cref="MonadZero.Lift{T1, T2, TResult}"/>
        public static MonadZero <TResult> ZipWith <T1, T2, TResult>(
            this MonadZero <T1> @this,
            MonadZero <T2> 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))));
        }