-
Notifications
You must be signed in to change notification settings - Fork 1
/
rx-operators.ads
183 lines (141 loc) · 6.28 KB
/
rx-operators.ads
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
with Rx.Observables;
with Rx.Op.Count;
with Rx.Impl.Transformers;
private with Rx.Op.Flatmap;
private with Rx.Op.Map;
private with Rx.Op.Scan;
generic
-- These could well be trait packages, but using those the user only has to know about "observables" packages
with package From is new Rx.Observables (<>); -- Naming chosen for same length
with package Into is new Rx.Observables (<>);
package Rx.Operators is
-- This package seems unnecessary but by separating it from Transform we can too separate each operator
-- implementation classes in its own packages, just like with Typed/Observables hierarchy.
package Typed is new Rx.Impl.Transformers (From.Typed, Into.Typed);
package Typed_Lists is new Rx.Impl.Transformers (From.Typed_Lists, Into.Typed);
subtype Operator Is Typed.Operator'Class;
procedure Diagnose (This : Into.Observable'Class);
-- Experimental dump of This chain
-- The chain is expected to be formed by
-- From.Operator'Class, (any amount)
-- Typed.Operator'Class,(one)
-- Into.Operator'Class, (any amount)
--------------
-- Counters --
--------------
generic
with function Succ (V : Into.T) return Into.T;
Default_Initial_Count : Into.T;
package Counters is
package Pkg_Count is new Rx.Op.Count (Typed, Succ, Default_Initial_Count);
function Count (First : Into.T) return Operator renames Pkg_Count.Count;
end Counters;
--------------
-- Flat_Map --
--------------
function Flat_Map (Func : Typed.Actions.Inflater1)
return Typed.Operator'Class;
function Flat_Map (Func : Typed.Actions.TInflater1'Class)
return Typed.Operator'Class;
function Flat_Map (Pipeline : Into.Observable'Class)
return Typed.Operator'Class;
-- Subscribes to Just (V) & Pipeline
-- Pipeline must be of ...-AA-AA-AB-BB-BB-... for types to match at runtime
-- Pipeline must be made of all Operator'Class
-- See notes in Rx.Op.Flat_Map for more detail
------------
-- Length --
------------
generic
with function Length (V : From.Typed_Lists.T) return Into.T;
function Length return Typed_Lists.Operator'Class;
---------
-- Map --
---------
function Map (F : Typed.Actions.Func1) return Operator'Class;
----------
-- Scan --
----------
function Scan (F : Typed.Actions.Func2;
Seed : Into.T;
Emit_Seed : Boolean) return Operator'Class;
----------
-- Size --
----------
generic
with function Size (V : From.T) return Into.T;
function Size return Operator'Class;
---------
-- "&" --
---------
function "&" (L : From.Observable; R : Operator) return Into.Observable
renames Typed.Concatenate;
function "&" (L : From.Observable; R : Typed.Actions.Func1) return Into.Observable;
-- Implicit Map
function "&" (Producer : From.Observable'Class;
Consumer : Typed.Actions.Inflater1)
return Into.Observable'Class;
-- Implicit Flat_Map
function "&" (Producer : From.Observable'Class;
Consumer : Typed.Actions.TInflater1'Class)
return Into.Observable'Class;
-- Implicit Flat_Map
package Linkers is
-- Analog to the one in Observables
function "&" (L : From.Observable; R : Operator) return Into.Observable
renames Typed.Concatenate;
function "&" (L : From.Observable; R : Typed.Actions.Func1) return Into.Observable
renames Operators."&";
function "&" (Producer : From.Observable'Class;
Consumer : Typed.Actions.Inflater1)
return Into.Observable'Class renames Operators."&";
function "&" (Producer : From.Observable'Class;
Consumer : Typed.Actions.TInflater1'Class)
return Into.Observable'Class renames Operators."&";
end Linkers;
private
function Identity (Unused : Typed.From.Observer'Class) return Typed.Into.Observer'Class is
(raise Program_Error with "identity unavailable in Transformer context");
procedure Set_Parent (This : in out Into.Observable'Class;
Parent : From.Observable'Class);
-- Cross-type Concatenate: used to be able to supply AA-AA-AB-BB-BB chains
-- to Flat_Map. Thus, at some point in the upstream of This, an AB operator
-- must exist, with optional AA before it, that can observe givent Parent.
-- Here, we navigate upstream from This (all must be Operator'Class), and
-- finally set Parent as parent of the first upstream.
-- See also Diagnose, which does something similar (simpler) for diagnostics.
---------------
-- RxFlatMap --
---------------
package RxFlatMap is new Rx.Op.Flatmap (Typed,
Identity, Typed.Broken_Identity,
Set_Parent);
function Flat_Map (Func : Typed.Actions.Inflater1)
return Typed.Operator'Class is
(RxFlatMap.Create (Func, Recursive => False));
function Flat_Map (Func : Typed.Actions.TInflater1'Class)
return Typed.Operator'Class is
(RxFlatMap.Create (Func, Recursive => False));
function Flat_Map (Pipeline : Into.Observable'Class)
return Typed.Operator'Class is
(RxFlatMap.Create (Pipeline, Recursive => False));
function "&" (Producer : From.Observable'Class;
Consumer : Typed.Actions.Inflater1)
return Into.Observable'Class renames RxFlatMap."&";
function "&" (Producer : From.Observable'Class;
Consumer : Typed.Actions.TInflater1'Class)
return Into.Observable'Class renames RxFlatMap."&";
-----------
-- RxMap --
-----------
package RxMap is new Rx.Op.Map (Typed);
function Map (F : Typed.Actions.Func1) return Operator renames RxMap.Create;
function "&" (L : From.Observable; R : Typed.Actions.Func1) return Into.Observable renames RxMap."&";
------------
-- RxScan --
------------
package RxScan is new Rx.Op.Scan (Typed);
function Scan (F : Typed.Actions.Func2;
Seed : Into.T;
Emit_Seed : Boolean) return Operator renames RxScan.Create;
end Rx.Operators;