예제 #1
0
        public static Mayhap <TResult> SelectMany <T, TMiddle, TResult>(
            this Mayhap <T> @this,
            Func <T, Mayhap <TMiddle> > selector,
            Func <T, TMiddle, TResult> resultSelector)
        {
            Utilities.Guard.NotNull(selector, nameof(selector));
            Utilities.Guard.NotNull(resultSelector, nameof(resultSelector));

            return(@this.Bind(
                       x => selector(x).Select(
                           middle => resultSelector(x, middle))));
        }
예제 #2
0
        /// <summary>
        /// (&lt;**&gt;)
        /// <para>A variant of (&lt;*&gt;) with the arguments reversed.</para>
        /// </summary>
        public static Mayhap <TResult> Apply <TSource, TResult>(
            this Mayhap <TSource> @this,
            Mayhap <Func <TSource, TResult> > applicative)
        {
            // (<**>) :: Applicative f => f a -> f (a -> b) -> f b
            // (<**>) = liftA2(\a f -> f a)
            //
            // A variant of '<*>' with the arguments reversed.

#if STRICT_HASKELL
            return(Invoke(applicative, @this));
#else
            return(applicative.Bind(f => @this.Select(f)));
#endif
        }