/// <summary> /// Starts the asynchronous computation in the thread pool. Await result on AsyncReplyChannel. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="m"></param> /// <param name="f">The lambda providing the AsyncReplyChannel</param> /// <returns></returns> public static Unit StartAndReply <T>(this Async <T> m, Func <AsyncReplyChannel <T>, AsyncReplyChannel <T> > f) { var ch = f(new AsyncReplyChannel <T>(_ => Unit.Default)); m.Bind <T, Unit>(v => { ch.Reply(v); return(() => Unit.Default); }).Start(); return(Unit.Default); }
// Functor functions /// <summary> /// Applies f to the result of m /// </summary> /// <typeparam name="TInput"></typeparam> /// <typeparam name="TOutput"></typeparam> /// <param name="m"></param> /// <param name="f"></param> /// <returns></returns> public static Async <TOutput> Map <TInput, TOutput>(this Async <TInput> m, Func <TInput, TOutput> f) { return(m.Bind <TInput, TOutput>(v => () => f(v))); }
/// <summary> /// Runs m then returns h /// </summary> /// <typeparam name="TInput"></typeparam> /// <typeparam name="TOutput"></typeparam> /// <param name="m"></param> /// <param name="h"></param> /// <returns></returns> public static Async <TOutput> Then <TInput, TOutput>(this Async <TInput> m, Async <TOutput> h) { return(m.Bind(_ => h)); }