tablesaw
tablesaw copied to clipboard
Add support for not() to where()
In where() try to make a decent implementation of not(). Currently you have to use flip() providing the rowcount as an argument.
Maybe there is a way to have the rowcount injected? Since generally (IIRC) query clauses are split and executed independently perhaps this is a spot for handling the injection.
Besides flip(), there is an .andNot()
operator that works like .and()
and .or()
, but no .orNot().
This should be added so you can express "either a or not (b)".
There is also the entire "queryHelper" system, which has a not() operator and infers the table reference so you don't have to say
table.stringColumn("foo")....
and can say instead stringColumn("foo")...
There are many negated operators like .isNotEqual
and .isNotIn
that minimize the need for not.
There is also the dropWhere()
variation on .where()
that negates everything that follows
None of these is a real replacement for a not
that works with the main query system and you can drop into the regular query system around any clause, but it does explain why I so rarely miss that.
Basically the only time you need not but it isn't available is when you want to negate a multi-clause phrase like not(z>4 and y < 12) and you want it to be the first clause.
It would not be better to have all functions working only in one way (i.e., without the negated form also existing), remove andNot
, and just have this Not
clause that may work anywhere? Or even allow for taking generic predicates (lambdas) as parameters in all related functions, so the caller can just write any predicate they want and negate it or not inside the function?