/// <summary> /// Implements the canonical bind operation /// </summary> /// <typeparam name="X">The source domain type</typeparam> /// <typeparam name="Y">The target domain type</typeparam> /// <param name="x">The point in the monadic space over X</param> /// <param name="f">The function to apply to effect the bind</param> /// <returns></returns> public static Option <Y> bind <X, Y>(Option <X> x, Func <X, Option <Y> > f) { if (x) { var y = f(x.ValueOrDefault()); var m = AppMessage.Combine(x.Message, y.Message); return(y.WithMessage(m)); } else { return(None <Y>(x.Message)); } }
/// <summary> /// Combines two messages to create a new message /// </summary> /// <param name="m1">The first message</param> /// <param name="m2">The second message</param> /// <returns></returns> public static IAppMessage combine(IAppMessage m1, IAppMessage m2) => AppMessage.Combine(m1, m2);