Restrict

Predicate-based filtering

Signature

restrict(operand: Relation, predicate: Predicate) -> Relation

Examples

restrict(suppliers, city: 'Paris', status: 20)
restrict(suppliers, eq(city: 'Paris') & gt(:status, 20))
restrict(suppliers, ->(t){ t.city == 'Paris' and t.status > 20 })

Description

Computes a relation as a subset of operand tuples for which a tuple predicate evaluates to TRUE.

Implementation notes

As of current Alf version, native predicates (through ruby Proc objects) cannot be optimized nor compiled to SQL. The use of predicate factories (eq, gt, etc.) is strongly recommended.