I have a kind of chain of validators that I need to run on my app:
public class Validator1 : IValidator
{
public IObservable<ValidatorResult> Validate()
{
....
}
}
...
public class Validator2 : IValidator // this validator will return a fail
...
public class Validator3 : IValidator
...
Now I need to run them in sequence until one fails(ValidatorResult.Status == Status.Fail
).
A Where
was my first thought, but of course, it's not a good solution for this because it will kill the whole chain.
So I tried something like
Validator1.Validate(address)
.Concat(Validator2.Validate(address)).Where(x => x.Status == ValidatorStatus.Successful)
.Concat(Validator3.Validate(address))
But that results in the Validator2
not been included in the final chain, and the Validator3
end up being called anyway.
So, what I wanted here is that the signal from Validator1 and Validator2 would hit my Subscribe()
, but nothing after that.