Refactor the handling of arrays in where predicates

Simplifies the code slightly, isolates non-nil non-range values into a
single array, which will make it easier to do things like apply type
casting to them in the future.
Merge pull request #15350 from sgrif/sg-refactor-predicate-builder

Refactor the handling of arrays in where predicates