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))))); }
/// <summary> /// Lifts function f from Tvalue =< TResult to Maybe>TValue< =< Maybe>TResult<, 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>TSelector< /// </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)))));; }
public static IMaybe <TResult> Select <TValue, TResult>(this IMaybe <TValue> m, Func <TValue, TResult> f) { return(m.SelectMany(a => new Just <TResult>(f(a)))); }
public static IMaybe <T2> Apply <T1, T2>(this IMaybe <Func <T1, T2> > fa, IMaybe <T1> ma) { return(fa.SelectMany(ma.Select)); }
/// <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)); }
public static IMaybe <T> Where <T>(this IMaybe <T> m, Func <T, bool> predicate) { return(m.SelectMany(t => predicate(t) ? m : None <T>())); }
public static IMaybe <U> SelectMany <T, U>(this IMaybe <T> m, Func <T, U?> binder) where U : struct { return(m.SelectMany(binder, StandardFunctions.IdValueSelector)); }