Closed mkaemmerer closed 10 years ago
Good stuff. Would it be possible to build the matcher context in one place instead of modifying it afterwards in asMatchers
? This would also make .not()
work as expected as it does with other .is()
and .where()
matchers. I think this kind of consistency in the API would be good.
Great points! Will refactor when I have time.
I lifted the definitions of some/every from asMatchers to addMatchers. I couldn't figure out a decent way to move it into addPositiveMatchers yet, so there's still some duplication.
IMO it would serve the purpose to just negate the value of the end result stream so that
stream.is().every(fs).not()
would produce the same values as
stream.is().not().every(fs)
Does this help with reducing the duplication?
Not quite. It's fine for is
but doesn't work for where
.
This:
stream.where().not().every(fs)
is not the same as this:
stream.where().every(fs).not()
Ah, of course, totally missed that.
So you can't just negate the operation's result, although it should be possible to negate the result of isEvery and isSome streams and then use those.
Because of DeMorgan's laws you don't need to do this in not
matches = Bacon._.map(((f) -> f(stream).not()), fs)
isEvery = Bacon._.fold(matches, Bacon.constant(false), (x,y) -> x.or(y))
because this is the same, right?
matches = Bacon._.map(((f) -> f(stream)), fs)
isEvery = Bacon._.fold(matches, Bacon.constant(false), (x,y) -> x.and(y)).not()
So you could partially re-use the positive every/some by extracting functions that return the boolean property.
Or are my tired eyes still missing something? :)
I'm pretty sure that works correctly. My tests seem to think so too :)
Ooops. Fixed now.
Released version 0.4.0.
Adds matchers "some" and "every" for matching multiple conditions at once.