public static AsyncMiddleware <TContext, TResult> Choose <TContext, TResult>( this IEnumerable <AsyncMiddleware <TContext, TResult> > choices, Func <TResult, TContext, Task <bool> > wasChosen, AsyncMiddleware <TContext, TResult> defaultAction) => async(context, next, ct) => { foreach (var middleware in choices) { var result = await middleware(context, next, ct); if (await wasChosen(result, context)) { return(result); } } return(await defaultAction(context, next, ct)); };
public static AsyncMiddleware <TContext, TResult> Compose <TContext, TResult>( this AsyncMiddleware <TContext, TResult> middleware, params AsyncMiddleware <TContext, TResult>[] middlewares) => middleware.Singleton().Concat(middlewares).Compose();
public static AsyncMiddlewareFunc <TContext, TResult> Combine <TContext, TResult>( this AsyncMiddleware <TContext, TResult> middleware, SimpleAsyncMiddlewareFunc <TContext, TResult> func) => (context, ct) => middleware(context, (c, _) => func(c), ct);
public static AsyncMiddlewareFunc <TContext, TResult> Combine <TContext, TResult>( this AsyncMiddleware <TContext, TResult> middleware, AsyncMiddlewareFunc <TContext, TResult> func) => (context, ct) => middleware(context, func, ct);