1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use fmt;
/// The Apache TinkerPop `Scope` token: whether a step works on the whole stream (`Global`) or on
/// the collection held by each single traverser (`Local`).
///
/// `Scope::Local` treats the one incoming object as a collection: a list is processed
/// element-wise, a map entry-wise (where the step defines it), and any other value as a
/// one-element collection. `Scope::Global` is the ordinary stream-wide step, so
/// `sum_scoped(Scope::Global)` is exactly `sum()`.
///
/// In the Rust API a scoped step is spelled `<step>_scoped(scope, ...)`, in the Rhai DSL
/// `Scope.local` / `Scope.global` (or `Scope::local` / `Scope::global`), for example
/// `g.V().values("age").fold().sum(Scope.local)`.
///
/// ```rust
/// use graphersal::prelude::*;
///
/// let graph = GraphSource::tinkerpop_modern();
/// let lock = graph.read();
/// let total = lock
/// .traversal()
/// .v(None::<()>)
/// .values("age")
/// .fold()
/// .sum_scoped(Scope::Local)
/// .to_list()
/// .unwrap();
/// assert_eq!(total, vec![ElementProperty::Number(123.into())]);
/// ```
///
/// Name clash: the embedded script engine has its own `rhai::Scope` (a variable scope). Code that
/// glob-imports `graphersal::prelude::*` and also needs Rhai's type imports `rhai::Scope`
/// explicitly (an explicit import shadows the glob one) or refers to this token by its full path
/// `graphersal::prelude::Scope`.
///
/// Closed set, so deliberately not `#[non_exhaustive]`: TinkerPop defines exactly these two scopes.