Skip to content

Commit

Permalink
Add a passthrough leaper
Browse files Browse the repository at this point in the history
  • Loading branch information
ecstatic-morse committed Aug 20, 2021
1 parent 5bda2f0 commit 9da0d0f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 19 additions & 0 deletions src/treefrog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Tuple>() -> PrefixFilter<Tuple, fn(&Tuple) -> 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
Expand Down

0 comments on commit 9da0d0f

Please sign in to comment.