Exemplo n.º 1
0
        // Choose

        public static SyncMiddleware <TContext, TResult> Choose <TContext, TResult>(
            this IEnumerable <SyncMiddleware <TContext, TResult> > choices,
            Func <TResult, TContext, bool> wasChosen,
            SyncMiddleware <TContext, TResult> defaultAction) =>
        (context, next) =>
        {
            foreach (var middleware in choices)
            {
                var result = middleware(context, next);

                if (wasChosen(result, context))
                {
                    return(result);
                }
            }

            return(defaultAction(context, next));
        };
Exemplo n.º 2
0
 public static SyncMiddleware <TContext, TResult> Compose <TContext, TResult>(
     this SyncMiddleware <TContext, TResult> middleware,
     params SyncMiddleware <TContext, TResult>[] middlewares) =>
 middleware.Singleton().Concat(middlewares).Compose();
Exemplo n.º 3
0
 public static SyncMiddlewareFunc <TContext, TResult> Combine <TContext, TResult>(
     this SyncMiddleware <TContext, TResult> middleware,
     SyncMiddlewareFunc <TContext, TResult> func) =>
 context => middleware(context, func);