Skip to content

Commit 4917246

Browse files
Add from_join_first methods to help with 1-tuple prefixes
1 parent e28a0d4 commit 4917246

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/relation.rs

+19
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,25 @@ impl<Tuple: Ord> Relation<Tuple> {
6262
join::join_into_relation(input1, input2, logic)
6363
}
6464

65+
/// An small wrapper around [`Relation::from_join`] that uses the first element of `A` and `B`
66+
/// as the shared prefix.
67+
///
68+
/// This is useful because `Split` needs a tuple, and working with 1-tuples is a pain.
69+
/// It can also help with inference in cases where `logic` does not make use of the shared
70+
/// prefix.
71+
pub fn from_join_first<P, A, B>(
72+
input1: &Relation<A>,
73+
input2: &Relation<B>,
74+
mut logic: impl FnMut(P, A::Suffix, B::Suffix) -> Tuple,
75+
) -> Self
76+
where
77+
P: Ord,
78+
A: Copy + Split<(P,)>,
79+
B: Copy + Split<(P,)>,
80+
{
81+
join::join_into_relation(input1, input2, |(p,), a, b| logic(p, a, b))
82+
}
83+
6584
/// Creates a `Relation` by removing all values from `input1` that
6685
/// share a key with `input2`, and then transforming the resulting
6786
/// tuples with the `logic` closure. Like

src/variable.rs

+19
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,25 @@ impl<Tuple: Ord> Variable<Tuple> {
103103
join::join_into(input1, input2, self, logic)
104104
}
105105

106+
/// An small wrapper around [`Variable::from_join`] that uses the first element of `A` and `B`
107+
/// as the shared prefix.
108+
///
109+
/// This is useful because `Split` needs a tuple, and working with 1-tuples is a pain.
110+
/// It can also help with inference in cases where `logic` does not make use of the shared
111+
/// prefix.
112+
pub fn from_join_first<'me, P, A, B>(
113+
&self,
114+
input1: &'me Variable<A>,
115+
input2: impl JoinInput<'me, B>,
116+
mut logic: impl FnMut(P, A::Suffix, B::Suffix) -> Tuple,
117+
) where
118+
P: Ord,
119+
A: Copy + Split<(P,)>,
120+
B: Copy + Split<(P,)>,
121+
{
122+
join::join_into(input1, input2, self, |(p,), a, b| logic(p, a, b))
123+
}
124+
106125
/// Same as [`Variable::from_join`], but lets you ignore some of the resulting tuples.
107126
///
108127
/// # Examples

0 commit comments

Comments
 (0)