public static IMaybe <TResult> SelectMany <T, U, TResult>(
     this IMaybe <T> source,
     Func <T, IMaybe <U> > k,
     Func <T, U, TResult> s)
 {
     return(source
            .SelectMany(x => k(x)
                        .SelectMany(y => new Just <TResult>(s(x, y)))));
 }
Exemple #2
0
 /// <summary>
 /// Lifts function f from Tvalue =&lt; TResult to Maybe&gt;TValue&lt; =&lt; Maybe&gt;TResult&lt;, applies it, and then applies the lifted selector
 /// </summary>
 /// <typeparam name="TValue">The type wrapped in initial Maybe m </typeparam>
 /// <typeparam name="TResult">The type returned by f</typeparam>
 /// <typeparam name="TSelector">The type of the value returned by selector</typeparam>
 /// <param name="m">A Maybe of TValue</param>
 /// <param name="f">Function to lift</param>
 /// <param name="selector">Transformation function</param>
 /// <returns>
 /// IMaybe&gt;TSelector&lt;
 /// </returns>
 public static IMaybe <TSelector> SelectMany <TValue, TResult, TSelector>(this IMaybe <TValue> m, Func <TValue, IMaybe <TResult> > f, Func <TValue, TResult, TSelector> selector)
 {
     return(m.SelectMany(a => f(a).SelectMany(b => new Just <TSelector>(selector(a, b)))));;
 }
Exemple #3
0
 public static IMaybe <TResult> Select <TValue, TResult>(this IMaybe <TValue> m, Func <TValue, TResult> f)
 {
     return(m.SelectMany(a => new Just <TResult>(f(a))));
 }
Exemple #4
0
 public static IMaybe <T2> Apply <T1, T2>(this IMaybe <Func <T1, T2> > fa, IMaybe <T1> ma)
 {
     return(fa.SelectMany(ma.Select));
 }
Exemple #5
0
 /// <summary>
 /// Select out the possible unknowns into a single unknown
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="m">maybe of maybe of type T</param>
 /// <returns>maybe of type T</returns>
 public static IMaybe <T> Join <T>(this IMaybe <IMaybe <T> > m)
 {
     return(m.SelectMany(BasicFunctions.Identity));
 }
Exemple #6
0
 public static IMaybe <T> Where <T>(this IMaybe <T> m, Func <T, bool> predicate)
 {
     return(m.SelectMany(t => predicate(t) ? m : None <T>()));
 }
Exemple #7
0
 public static IMaybe <U> SelectMany <T, U>(this IMaybe <T> m, Func <T, U?> binder)
     where U : struct
 {
     return(m.SelectMany(binder, StandardFunctions.IdValueSelector));
 }