Skip to content

Commit 9da0d0f

Browse files
Add a passthrough leaper
1 parent 5bda2f0 commit 9da0d0f

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub use crate::{
2929
extend_with::ExtendWith,
3030
filter_anti::FilterAnti,
3131
filter_with::FilterWith,
32-
filters::{PrefixFilter, ValueFilter},
32+
filters::{passthrough, PrefixFilter, ValueFilter},
3333
Leaper, Leapers, RelationLeaper,
3434
},
3535
variable::Variable,

src/treefrog.rs

+19
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,25 @@ pub(crate) mod filters {
190190
}
191191
}
192192

193+
/// Returns a leaper that proposes a single copy of each tuple from the main input.
194+
///
195+
/// Use this when you don't need any "extend" leapers in a join, only "filter"s. For example,
196+
/// in the following datalog rule, all terms in the second and third predicate are bound in the
197+
/// first one (the "main input" to our leapjoin).
198+
///
199+
/// ```prolog
200+
/// error(loan, point) :-
201+
/// origin_contains_loan_at(origin, loan, point), % main input
202+
/// origin_live_at(origin, point),
203+
/// loan_invalidated_at(loan, point).
204+
/// ```
205+
///
206+
/// Without a passthrough leaper, neither the filter for `origin_live_at` nor the one for
207+
/// `loan_invalidated_at` would propose any tuples, and the leapjoin would panic at runtime.
208+
pub fn passthrough<Tuple>() -> PrefixFilter<Tuple, fn(&Tuple) -> bool> {
209+
PrefixFilter::from(|_| true)
210+
}
211+
193212
/// A treefrog leaper based on a predicate of prefix and value.
194213
/// Use like `ValueFilter::from(|tuple, value| ...)`. The closure
195214
/// should return true if `value` ought to be retained. The

0 commit comments

Comments
 (0)