-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache-fp-poc.xml
313 lines (269 loc) · 9.06 KB
/
cache-fp-poc.xml
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
<?xml version="1.0" encoding="UTF8"?>
<Export generator="Cache" version="25">
<Class name="FP.Common">
<Abstract>1</Abstract>
<TimeCreated>64468,52545.15514</TimeCreated>
<Property name="Content">
<Type>%CacheString</Type>
<Private>1</Private>
</Property>
<Method name="Result">
<ReturnType>%CacheString</ReturnType>
<Implementation><![CDATA[ quit ..Content
]]></Implementation>
</Method>
</Class>
<Class name="FP.Functor">
<Super>%RegisteredObject,FP.Common</Super>
<TimeCreated>64468,40072.097404</TimeCreated>
<Method name="%OnNew">
<FormalSpec>mappable:%RegisteredObject</FormalSpec>
<Private>1</Private>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
set ..Content = mappable
quit $$$OK
]]></Implementation>
</Method>
<Method name="From">
<ClassMethod>1</ClassMethod>
<FormalSpec>mappable:%RegisteredObject</FormalSpec>
<ReturnType>FP.Monoid</ReturnType>
<Implementation><![CDATA[
set functor = ..%New(mappable)
quit ##class(FP.Monoid).%New(functor)
]]></Implementation>
</Method>
</Class>
<Class name="FP.Monoid">
<Super>%RegisteredObject</Super>
<TimeCreated>64468,57729.347019</TimeCreated>
<Property name="Functor">
<Type>FP.Functor</Type>
<Private>1</Private>
</Property>
<Method name="%OnNew">
<FormalSpec>functor:FP.Functor</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
set ..Functor = functor
quit $$$OK
]]></Implementation>
</Method>
<Method name="PushValue">
<Internal>1</Internal>
<FormalSpec>mappable:%RegisteredObject,item:%CacheString</FormalSpec>
<Private>1</Private>
<Implementation><![CDATA[
if mappable.%IsA("%DynamicArray") {
do mappable.%Push(item)
} else {
do mappable.Insert(item)
}
]]></Implementation>
</Method>
<Method name="GetFunctorLength">
<Internal>1</Internal>
<FormalSpec>functorValue:%RegisteredObject</FormalSpec>
<Private>1</Private>
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[
if functorValue.%IsA("%DynamicArray") {
quit functorValue.%Size()
}
quit functorValue.Count()
]]></Implementation>
</Method>
<Method name="GetFunctorItem">
<Internal>1</Internal>
<FormalSpec>functorValue:%RegisteredObject,index:%Integer</FormalSpec>
<Private>1</Private>
<ReturnType>%CacheString</ReturnType>
<Implementation><![CDATA[
if functorValue.%IsA("%DynamicArray") {
quit functorValue.%Get(index - 1)
}
quit functorValue.GetAt(index)
]]></Implementation>
</Method>
<Method name="Map">
<FormalSpec>monoid:%String,params...:%String</FormalSpec>
<ReturnType>FP.Functor</ReturnType>
<Implementation><![CDATA[
#dim item As %RegisteredObject
set functorValue = ..Functor.Result()
set mappable = $System.OBJ.New($classname(functorValue))
set className = $piece(monoid, ":", 1)
set classMethod = $piece(monoid, ":", 2)
for i=1:1:..GetFunctorLength(functorValue) {
set item = ..GetFunctorItem(functorValue, i)
set result = $classmethod(className, classMethod, item.%ConstructClone(1), i, params...)
do ..PushValue(mappable, result)
}
quit ##class(FP.Functor).From(mappable)
]]></Implementation>
</Method>
<Method name="Filter">
<FormalSpec>monoid:%String,params...:%String</FormalSpec>
<Implementation><![CDATA[
set functorValue = ..Functor.Result()
set mappable = $System.OBJ.New($classname(functorValue))
set className = $piece(monoid, ":", 1)
set classMethod = $piece(monoid, ":", 2)
for i=1:1:..GetFunctorLength(functorValue) {
set item = ..GetFunctorItem(functorValue, i)
set passed = $classmethod(className, classMethod, item.%ConstructClone(1), i, params...)
if passed = 1 {
do ..PushValue(mappable, item)
}
}
quit ##class(FP.Functor).From(mappable)
]]></Implementation>
</Method>
<Method name="Some">
<FormalSpec>monoid:%String,params...:%String</FormalSpec>
<ReturnType>FP.Functor</ReturnType>
<Implementation><![CDATA[
set className = $piece(monoid, ":", 1)
set classMethod = $piece(monoid, ":", 2)
set functorValue = ..Functor.Result()
set passed = 0
for i=1:1:..GetFunctorLength(functorValue) {
set item = ..GetFunctorItem(functorValue, i)
set passed = $classmethod(className, classMethod, item.%ConstructClone(1), i, params...)
if passed = 1 quit
}
quit ##class(FP.Value).%New(passed)
]]></Implementation>
</Method>
<Method name="Every">
<FormalSpec>monoid:%String,params...:%String</FormalSpec>
<ReturnType>FP.Functor</ReturnType>
<Implementation><![CDATA[
set className = $piece(monoid, ":", 1)
set classMethod = $piece(monoid, ":", 2)
set passed = 1
set functorValue = ..Functor.Result()
for i=1:1:..GetFunctorLength(functorValue) {
set item = ..GetFunctorItem(functorValue, i)
set passed = $classmethod(className, classMethod, item.%ConstructClone(1), i, params...)
if passed = "" || (passed = 0) quit
}
quit ##class(FP.Value).%New(passed)
]]></Implementation>
</Method>
<Method name="Reduce">
<FormalSpec>monoid:%String,initialAccumulated:%CacheString,params...:%String</FormalSpec>
<Implementation><![CDATA[
set className = $piece(monoid, ":", 1)
set classMethod = $piece(monoid, ":", 2)
set accumulated = initialAccumulated
set functorValue = ..Functor.Result()
for i=1:1:..GetFunctorLength(functorValue) {
set item = ..GetFunctorItem(functorValue, i)
set accumulated = $classmethod(className, classMethod, accumulated, item.%ConstructClone(1), i, functorValue, params...)
}
if $isobject(accumulated) && (accumulated.%Extends("%Collection.AbstractList") || accumulated.%Extends("%DynamicArray")) {
quit ##class(FP.Functor).From(accumulated)
}
quit ##class(FP.Value).%New(accumulated)
]]></Implementation>
</Method>
<Method name="ReduceRight">
<FormalSpec>monoid:%String,initialAccumulated:%CacheString,params...:%String</FormalSpec>
<Implementation><![CDATA[
set className = $piece(monoid, ":", 1)
set classMethod = $piece(monoid, ":", 2)
set accumulated = initialAccumulated
set functorValue = ..Functor.Result()
for i=..GetFunctorLength(functorValue):-1:1 {
set item = ..GetFunctorItem(functorValue, i)
set accumulated = $classmethod(className, classMethod, accumulated, item.%ConstructClone(1), i, functorValue, params...)
}
if $isobject(accumulated) && (accumulated.%Extends("%Collection.AbstractList") || accumulated.%Extends("%DynamicArray")) {
quit ##class(FP.Functor).From(accumulated)
}
quit ##class(FP.Value).%New(accumulated)
]]></Implementation>
</Method>
<Method name="Result">
<ReturnType>%CacheString</ReturnType>
<Implementation><![CDATA[ quit ..Functor.Result()
]]></Implementation>
</Method>
</Class>
<Class name="FP.Sample">
<Abstract>1</Abstract>
<TimeCreated>64468,58877.341662</TimeCreated>
<Method name="Demo">
<ClassMethod>1</ClassMethod>
<FormalSpec>item</FormalSpec>
<Implementation><![CDATA[
set array = []
for i=1:1:10000 {
set proxy = ##class(%ZEN.proxyObject).%New()
set proxy.value = i
do array.%Push(proxy)
}
set DoubleItemValue = $classname()_":DoubleItemValue"
set Odds = $classname()_":Odds"
set LowerThanFifty = $classname()_":LowerThanFifty"
set SumValues = $classname()_":SumValues"
// Doubles the value and filter any odd value.
set functor = ##class(FP.Functor).From(array).Map(DoubleItemValue).Filter(Odds)
// Removes any value that is higher than 50.
set lowerThanFiftyFunctor = functor.Filter(LowerThanFifty)
// Now sum the remaining values and get the result.
return lowerThanFiftyFunctor.Reduce(SumValues, 0).Result()
]]></Implementation>
</Method>
<Method name="DoubleItemValue">
<ClassMethod>1</ClassMethod>
<FormalSpec>item:%ZEN.proxyObject,i</FormalSpec>
<Implementation><![CDATA[
set item.value = (item.value * 2)
return item
]]></Implementation>
</Method>
<Method name="Odds">
<ClassMethod>1</ClassMethod>
<FormalSpec>item:%ZEN.proxyObject,i:%Integer</FormalSpec>
<Implementation><![CDATA[ return (i # 2 '= 0)
]]></Implementation>
</Method>
<Method name="LowerThanFifty">
<ClassMethod>1</ClassMethod>
<FormalSpec>item:%ZEN.proxyObject,i:%Integer</FormalSpec>
<Implementation><![CDATA[ return item.value <= 50
]]></Implementation>
</Method>
<Method name="SumValues">
<ClassMethod>1</ClassMethod>
<FormalSpec>accumulated:%Integer,item:%ZEN.proxyObject,i:%Integer,array:%RegisteredObject,params:%String</FormalSpec>
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[ return accumulated + item.value
]]></Implementation>
</Method>
</Class>
<Class name="FP.Value">
<Super>%RegisteredObject,FP.Common</Super>
<TimeCreated>64468,52692.752702</TimeCreated>
<Method name="%OnNew">
<FormalSpec>value:%CacheString=""</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
set ..Content = value
quit $$$OK
]]></Implementation>
</Method>
</Class>
<Project name="cache-fp-poc" LastModified="2017-07-04 17:39:23.557554" Target="##class(FP.Sample).Demo()" TargetType="0" HttpServer="http://localhost:57772">
<Items>
<ProjectItem name="FP.Common" type="CLS"></ProjectItem>
<ProjectItem name="FP.Functor" type="CLS"></ProjectItem>
<ProjectItem name="FP.Monoid" type="CLS"></ProjectItem>
<ProjectItem name="FP.Sample" type="CLS"></ProjectItem>
<ProjectItem name="FP.Value" type="CLS"></ProjectItem>
</Items>
</Project>
</Export>