Filtering with Predicates
In the previous chapter we matched patterns by specifying exact values like "Bulbasaur". Predicates let us filter rows using arbitrary truthy expressions.
A predicate clause is a function call wrapped in an extra pair of brackets:
Every variable used in the predicate must already be bound by an earlier pattern clause. Let's find all Pokemon with a speed stat above 100:
We can compare two bound variables against each other. Here are the Pokemon whose defense is strictly higher than their attack:
Predicates work on strings too, this site allows clojure.string/starts-with? and clojure.string/includes?; in a real Datomic app, any Clojure function is available. Here we find Pokemon whose name starts with "S":
Or find Pokemon whose name contains "saur":
Try: Combine two predicates to find Pokemon whose name starts with "S" and whose speed is above 100. Or find Pokemon whose attack and defense are both above 80.