Beispiel #1
0
 /// <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))
             );
     }));
 }
Beispiel #2
0
        /// <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);
        }