/// <summary> /// Monad instance for HaxlFetch. /// </summary> public static Haxl Bind(this Haxl fetch, Func <Scope, Haxl> bind) { return(Haxl.FromFunc((cache, logger) => { var result = fetch.Result(cache, logger); return result.Match( done => bind(done.AddToScope(Scope.New())).Result(cache, logger), blocked => Blocked.New(blocked.BlockedRequests, blocked.Continue.Bind(bind)) ); })); }
/// <summary> /// Converts a list of applicative groups into a Haxl monad. /// </summary> public static Haxl ToFetch(List <ApplicativeGroup> split, string parentBind, Scope parentScope) { if (parentScope == null) { parentScope = Scope.New(); } Haxl finalFetch = null; Action <Func <Scope, Haxl> > bindToFinal = f => { finalFetch = finalFetch == null?f(parentScope) : finalFetch.Bind(f); }; foreach (var applicative in split) { bindToFinal(ApplicativeToHaxl(applicative, parentBind)); } return(finalFetch); }