Combining Filters into One Predicate

Two successive order-preserving filters can select the same values as a conjunction when the tests are independent of effects and traversal history.

Source
Anbloq
Language
English
Created
Updated
Chapters
2
Reading time
1 min
In this article2 chapters
  1. Trace two tests
  2. Check predicate order

Trace two tests

On 2, 5, 6, 9, keep values over four to obtain 5, 6, 9. Keeping even values from that result yields 6. The combined filter checks both conditions for each candidate. Filtering loops set the output order.

Check predicate order

Short-circuit conjunction skips the second check for inputs failing the first. If the second test assumes a property verified by the first, preserve that order. See short-circuit evaluation.[1]

References

  1. Python Software Foundation, Functional Programming HOWTO ↩