Skip to content

Commit a96206c

Browse files
committed
add convenience Relation methods from_map and from_iter
Both are just simple wrappers that avoid the need of adding an import or using `collect`, etc
1 parent 64b06b7 commit a96206c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ impl<Tuple: Ord> Relation<Tuple> {
100100
Relation { elements }
101101
}
102102

103+
/// Creates a `Relation` from the elements of the `iterator`.
104+
///
105+
/// Same as the `from_iter` method from `std::iter::FromIterator` trait.
106+
pub fn from_iter<I>(iterator: I) -> Self
107+
where
108+
I: IntoIterator<Item = Tuple>
109+
{
110+
iterator.into_iter().collect()
111+
}
112+
103113
/// Creates a `Relation` using the `leapjoin` logic;
104114
/// see [`Variable::leapjoin`]
105115
pub fn from_leapjoin<'a, SourceTuple: Ord, Val: Ord + 'a>(
@@ -138,7 +148,7 @@ impl<Tuple: Ord> Relation<Tuple> {
138148
/// Construct a new relation by mapping another one. Equivalent to
139149
/// creating an iterator but perhaps more convenient. Analogous to
140150
/// `Variable::from_map`.
141-
pub fn from_map<T2: Ord>(&self, input: &Relation<T2>, logic: impl FnMut(&T2) -> Tuple) -> Self {
151+
pub fn from_map<T2: Ord>(input: &Relation<T2>, logic: impl FnMut(&T2) -> Tuple) -> Self {
142152
input.iter().map(logic).collect()
143153
}
144154

0 commit comments

Comments
 (0)