I’ve a design question around reactive extension, here is the scenario:
I’ve a car object and that car object has more than one validation objects. Each validation objects keep sending validation results to car class. Validation results can be Success or Error. When a validation sends Error I want to stop the car and when that same validation sends Success, I want to start the car again.
in other words:
All validations constantly sending validation results to car. If all validations are sending success I want the car keep going but if one of them sends error I want to stop the car till I receive success from that validation.
I’m trying to find a solution to this with reactive extensions.
Any ideas?
Thanks
Quite easy. If you have an
IEnumerable<IObservable<bool>>(could be an array or list of observables) calledxssthen you can do this:Now
combinedwill only betruewhen the latest value of all the observables istrue.Note that this will only produce a value when all of the source observables have produced a value. If you need a starting condition the source observables should have a default value provided using the
StartWithextension method.