standing_relations/convenience/
mod.rs

1use crate::{Dynamic, Op, Relation, Saved};
2
3pub mod concat;
4pub mod dynamic;
5pub mod feedback;
6pub mod input;
7pub mod join;
8pub mod map;
9pub mod output;
10pub mod pair;
11pub mod reduce;
12pub mod save;
13pub mod split;
14
15pub type Collection<'a, D> = Saved<Dynamic<'a, (D, isize)>>;
16
17impl<C: Op> Relation<C>
18where
19    C::D: Clone,
20{
21    pub fn collect<'a>(self) -> Collection<'a, C::D>
22    where
23        C: 'a,
24    {
25        self.dynamic().save()
26    }
27    /// No-op which nails down the expected item type.
28    ///
29    /// The compiler will complain if the provided type is wrong. This helps you spot type errors
30    /// where they occur rather than downstream.
31    ///
32    /// Example:
33    ///
34    /// ```
35    ///    use standing_relations::CreationContext;
36    ///    use std::{collections::HashMap, iter::FromIterator};
37    ///
38    ///    let mut context = CreationContext::new();
39    ///    let (_foo_input, foo) = context.new_input::<(char, isize)>();
40    ///    let (_bar_input, bar) = context.new_input::<char>();
41    ///    let foobar =
42    ///        foo.join(bar.counts()).flat_map(|(k,x,y)| if x < y {Some((k,x))} else {None});
43    ///    let foobar = foobar.t::<(char, isize)>();
44    /// ```
45    ///
46    /// Note that if instead of `flat_map`, we had accidentally used `map`, the compiler would
47    /// complain because `foobar` would have item type `Option<(char, isize)>` where we expect
48    /// `(char, isize)`.
49    pub fn t<D: Is<Myself = C::D>>(self) -> Self {
50        self
51    }
52}
53
54pub trait Is {
55    type Myself;
56}
57
58impl<T> Is for T {
59    type Myself = T;
60}