File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
RealTimeWeatherMonitoringApp/Infrastructure/Extension Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 1+ using RealTimeWeatherMonitoringApp . Domain . Interfaces ;
2+
3+ namespace RealTimeWeatherMonitoringApp . Infrastructure . Extension ;
4+
5+ public static class EvaluatorExtension
6+ {
7+ /// <summary>
8+ /// Composes multiple evaluators into a single evaluator that returns true only if all individual evaluators return true.
9+ /// </summary>
10+ /// <param name="evaluators">A collection of evaluators to be composed.</param>
11+ /// <returns>An evaluator that aggregates the evaluation results of all provided evaluators.</returns>
12+ public static IEvaluator < TEvaluated > EvaluateAll < TEvaluated > ( this IEnumerable < IEvaluator < TEvaluated > > evaluators ) =>
13+ new AllEvaluator < TEvaluated > ( evaluators ) ;
14+
15+ private class AllEvaluator < TEvaluated > : IEvaluator < TEvaluated >
16+ {
17+ private readonly IEnumerable < IEvaluator < TEvaluated > > _evaluators ;
18+ public AllEvaluator ( IEnumerable < IEvaluator < TEvaluated > > evaluators ) => _evaluators = evaluators ;
19+
20+ public bool Evaluate ( TEvaluated data ) => _evaluators . All ( evaluator => evaluator . Evaluate ( data ) ) ;
21+ }
22+ }
You can’t perform that action at this time.
0 commit comments