Any optimization for When + Unless on same condition?
See original GitHub issueSystem Details
- FluentValidation version: 8.0
Issue Description
Hi,
I’m looking to define several rules for when a condition is met, and several other rules for when that same condition is not met.
To do that, my code is currently:
WhenAsync(CheckConditionAsync, () => { /* rules */ });
UnlessAsync(CheckConditionAsync, () => { /* rules */ });
Checking the condition is an I/O bound job and therefore asynchronous, so for performance reasons I’d like to avoid doing that twice. Is there some way of doing that with the current version of FluentValidation?
If there isn’t, but maybe also if there is, could it be possible to extend the overloads of When
to include a 3rd parameter that would take another action for when the condition is not met? Or maybe to follow the fluent paradigm, make When return some interface that can chain an Otherwise
method.
Thanks
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
java - Optimizing conditional code inside nested for-loops
I would always go for the cleaner code over optimization (because it will be close to none if not none). The compiler will...
Read more >Multiple if condition optimization
Often I find conditional statements such as: if (life_max < max): if (expand): do life_max = max else: if (life_max > max) and...
Read more >Optimization problem with if condition as constraint
Assume finite bounds L≤bn−cn≤U. Introduce binary variables xn, yn, and zn, and impose the following linear constraints: xn+yn+zn=1for all ...
Read more >If and Only If. Performance Cost of Using If Statements…
I was looping over every element in a 2D array and increasing the count if the value was odd. Quite simple, and in...
Read more >Introduction to Optimization, and Optimality Conditions for ...
A necessary condition for local optimality is a statement of the form: “if. ¯ x must satisfy . . . ” Such a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Looks like this will be easier than I thought, will aim to get it into 8.1
First part of this is implemented in
b897d3b
. Now calls toWhen
,WhenAsync
,Unless
andUnlessAsync
on the root validator will cache the result of the predicate the first time it’s executed, so subsequent rules will recieve the cached value.Will next look to see about chaining on an
Otherwise
method.I’ll try and get to it for 8.2