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)))); }
/// <summary> /// (<**>) /// <para>A variant of (<*>) 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 }