From 9da0d0f2705867fab6b986a8b180fbe05fdb25c4 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Fri, 20 Aug 2021 10:37:42 -0700 Subject: [PATCH] Add a `passthrough` leaper --- src/lib.rs | 2 +- src/treefrog.rs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 4591df1..682a7df 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,7 +29,7 @@ pub use crate::{ extend_with::ExtendWith, filter_anti::FilterAnti, filter_with::FilterWith, - filters::{PrefixFilter, ValueFilter}, + filters::{passthrough, PrefixFilter, ValueFilter}, Leaper, Leapers, RelationLeaper, }, variable::Variable, diff --git a/src/treefrog.rs b/src/treefrog.rs index 8a3b5f2..bde0300 100644 --- a/src/treefrog.rs +++ b/src/treefrog.rs @@ -190,6 +190,25 @@ pub(crate) mod filters { } } + /// Returns a leaper that proposes a single copy of each tuple from the main input. + /// + /// Use this when you don't need any "extend" leapers in a join, only "filter"s. For example, + /// in the following datalog rule, all terms in the second and third predicate are bound in the + /// first one (the "main input" to our leapjoin). + /// + /// ```prolog + /// error(loan, point) :- + /// origin_contains_loan_at(origin, loan, point), % main input + /// origin_live_at(origin, point), + /// loan_invalidated_at(loan, point). + /// ``` + /// + /// Without a passthrough leaper, neither the filter for `origin_live_at` nor the one for + /// `loan_invalidated_at` would propose any tuples, and the leapjoin would panic at runtime. + pub fn passthrough() -> PrefixFilter bool> { + PrefixFilter::from(|_| true) + } + /// A treefrog leaper based on a predicate of prefix and value. /// Use like `ValueFilter::from(|tuple, value| ...)`. The closure /// should return true if `value` ought to be retained. The