|
53 | 53 | # The first one for the accumulator, the second one
|
54 | 54 | # for the element of the collection and the third one for the index.
|
55 | 55 | [start func] > reducedi
|
56 |
| - ^.origin.length > origin-len! |
57 | 56 | if. > @
|
58 |
| - 0.eq origin-len |
| 57 | + is-empty |
59 | 58 | start
|
60 |
| - rec-reduced start 0.as-bytes |
| 59 | + rec-reducedi origin |
61 | 60 |
|
62 |
| - [accum index] > rec-reduced |
63 |
| - index.as-number > idx-as-number |
64 |
| - 1.plus idx-as-number > next-index! |
| 61 | + [tup] > rec-reducedi |
65 | 62 | if. > @
|
66 |
| - next-index.eq ^.origin-len |
67 |
| - ^.func > accumulated |
68 |
| - accum |
69 |
| - ^.^.origin.at idx-as-number |
70 |
| - idx-as-number |
71 |
| - ^.rec-reduced |
72 |
| - accumulated |
73 |
| - next-index |
| 63 | + tup.length.eq 1 |
| 64 | + func |
| 65 | + start |
| 66 | + tup.value |
| 67 | + 0 |
| 68 | + func |
| 69 | + rec-reducedi tup.prev |
| 70 | + tup.value |
| 71 | + tup.prev.length |
74 | 72 |
|
75 | 73 | # Reduce from "start" using the function "func".
|
76 | 74 | # Here "func" must be an abstract object with two free attributes.
|
77 | 75 | # The first one for the accumulator, the second one for the element
|
78 | 76 | # of the collection.
|
79 | 77 | [start func] > reduced
|
80 |
| - ^.reducedi > @ |
| 78 | + reducedi > @ |
81 | 79 | start
|
82 |
| - ^.func accum item > [accum item idx] >> |
| 80 | + func accum item > [accum item idx] >> |
83 | 81 |
|
84 | 82 | # Map with index. Here "func" must be an abstract
|
85 | 83 | # object with two free attributes. The first
|
86 | 84 | # one for the element of the collection, the second one
|
87 | 85 | # for the index.
|
88 | 86 | [func] > mappedi
|
89 | 87 | list > @
|
90 |
| - ^.reducedi |
| 88 | + reducedi |
91 | 89 | *
|
92 | 90 | [accum item idx] >>
|
93 |
| - with. > @ |
94 |
| - accum |
95 |
| - ^.func item idx |
| 91 | + accum.with > @ |
| 92 | + func item idx |
96 | 93 |
|
97 | 94 | # Map without index. Here "func" must be an abstract
|
98 | 95 | # object with one free attribute, for the element
|
99 | 96 | # of the collection.
|
100 | 97 | [func] > mapped
|
101 |
| - ^.mappedi > @ |
102 |
| - ^.func item > [item idx] >> |
| 98 | + mappedi > @ |
| 99 | + func item > [item idx] >> |
103 | 100 |
|
104 | 101 | # For each collection element dataize the object
|
105 | 102 | # Here "func" must be an abstract object with
|
106 | 103 | # two free attributes: the element of the
|
107 | 104 | # collection and its index.
|
108 | 105 | # The result of `func` must be dataizable.
|
109 | 106 | [func] > eachi
|
110 |
| - ^.reducedi > @ |
| 107 | + reducedi > @ |
111 | 108 | true
|
112 | 109 | [acc item index] >>
|
113 | 110 | seq * > @
|
114 | 111 | acc
|
115 |
| - ^.func item index |
| 112 | + func item index |
116 | 113 |
|
117 | 114 | # For each collection element dataize the object
|
118 | 115 | # Here "func" must be an abstract object with
|
119 | 116 | # one free attribute, the element of the collection.
|
120 | 117 | [func] > each
|
121 |
| - ^.eachi > @ |
122 |
| - ^.func item > [item index] >> |
| 118 | + eachi > @ |
| 119 | + func item > [item index] >> |
123 | 120 |
|
124 | 121 | # Create a new list without the i-th element.
|
125 | 122 | [i] > withouti
|
126 | 123 | list > @
|
127 |
| - ^.reducedi |
| 124 | + reducedi |
128 | 125 | *
|
129 | 126 | [accum item idx] >>
|
130 | 127 | if. > @
|
131 |
| - ^.i.eq idx |
| 128 | + i.eq idx |
132 | 129 | accum
|
133 | 130 | accum.with item
|
134 | 131 |
|
135 | 132 | # Create a new list without the `element` which is `.eq` to given one.
|
136 | 133 | [element] > without
|
137 | 134 | list > @
|
138 |
| - ^.reduced |
| 135 | + reduced |
139 | 136 | *
|
140 | 137 | [accum item] >>
|
141 | 138 | if. > @
|
142 |
| - ^.element.eq item |
| 139 | + element.eq item |
143 | 140 | accum
|
144 | 141 | accum.with item
|
145 | 142 |
|
|
148 | 145 | [other] > eq
|
149 | 146 | and. > @
|
150 | 147 | eq.
|
151 |
| - ^.origin.length |
| 148 | + origin.length |
152 | 149 | other.length
|
153 |
| - ^.reducedi |
| 150 | + rec-eq origin other |
| 151 | + |
| 152 | + [first second] > rec-eq |
| 153 | + if. > @ |
| 154 | + first.length.eq 0 |
154 | 155 | true
|
155 |
| - [accum item idx] >> |
156 |
| - and. > @ |
157 |
| - accum |
158 |
| - eq. |
159 |
| - item |
160 |
| - ^.other.at idx |
| 156 | + and. |
| 157 | + first.value.eq second.value |
| 158 | + rec-eq first.prev second.prev |
161 | 159 |
|
162 | 160 | # Concatenates current list with given one.
|
163 | 161 | [passed] > concat
|
164 |
| - reduced. > @ |
165 |
| - list |
166 |
| - passed |
| 162 | + (list passed).reducedi > @ |
167 | 163 | ^
|
168 |
| - accum.with item > [accum item] |
| 164 | + accum.with item > [accum item index] |
169 | 165 |
|
170 | 166 | # Returns index of the first particular item in list.
|
171 | 167 | # If the list has no this item, index-of returns -1.
|
172 | 168 | [wanted] > index-of
|
173 |
| - ^.reducedi > @ |
| 169 | + reducedi > @ |
174 | 170 | -1
|
175 | 171 | [accum item index] >>
|
176 | 172 | if. > @
|
177 | 173 | and.
|
178 | 174 | -1.eq accum
|
179 |
| - item.eq ^.wanted |
| 175 | + item.eq wanted |
180 | 176 | index
|
181 | 177 | accum
|
182 | 178 |
|
183 | 179 | # Returns index of the last particular item in list.
|
184 | 180 | # If the list has no this item, returns -1.
|
185 | 181 | [wanted] > last-index-of
|
186 |
| - ^.reducedi > @ |
| 182 | + reducedi > @ |
187 | 183 | -1
|
188 | 184 | [accum item index] >>
|
189 | 185 | if. > @
|
190 |
| - item.eq ^.wanted |
| 186 | + item.eq wanted |
191 | 187 | index
|
192 | 188 | accum
|
193 | 189 |
|
|
197 | 193 | not. > @
|
198 | 194 | eq.
|
199 | 195 | -1
|
200 |
| - ^.index-of element |
| 196 | + index-of element |
201 | 197 |
|
202 | 198 | # Returns a new list sorted via `.lt` method.
|
203 | 199 | # @todo #3251:30min The object does not work. After moving `list` object
|
|
213 | 209 | # for the index. The result of dataization
|
214 | 210 | # the `func` should be boolean, that is `true` or `false`.
|
215 | 211 | [func] > filteredi
|
216 |
| - ^.origin.length > origin-length! |
217 | 212 | list > @
|
218 |
| - rec-filtered 0.as-bytes * |
| 213 | + rec-filteredi origin |
219 | 214 |
|
220 |
| - [idx-as-bytes accum] > rec-filtered |
221 |
| - ^.^.origin > original |
222 |
| - idx-as-bytes.as-number > index |
223 |
| - ^.^.origin.at index > item |
| 215 | + [tup] > rec-filteredi |
| 216 | + rec-filteredi tup.prev > next |
224 | 217 | if. > @
|
225 |
| - idx-as-bytes.eq ^.origin-length |
226 |
| - accum |
227 |
| - ^.rec-filtered |
228 |
| - (1.plus index).as-bytes |
229 |
| - if. |
230 |
| - ^.func item index |
231 |
| - accum.with item |
232 |
| - accum |
| 218 | + tup.length.eq 0 |
| 219 | + * |
| 220 | + if. |
| 221 | + func tup.value tup.prev.length |
| 222 | + next.with tup.value |
| 223 | + next |
233 | 224 |
|
234 | 225 | # Filter list without index with the function `func`.
|
235 | 226 | # Here `func` must be an abstract object
|
236 | 227 | # with one attribute for the element.
|
237 | 228 | # The result of dataization the `func`
|
238 | 229 | # should be boolean, that is `true` or `false`.
|
239 | 230 | [func] > filtered
|
240 |
| - ^.filteredi > @ |
241 |
| - ^.func item > [item index] >> |
| 231 | + filteredi > @ |
| 232 | + func item > [item index] >> |
242 | 233 |
|
243 |
| - # Get the first `index` elements from the start of the list. |
| 234 | + # Get the first `index` elements from the start of the list. todo |
244 | 235 | [index] > head
|
245 | 236 | index > idx!
|
246 | 237 | switch > @
|
|
268 | 259 | # Get the last `index` elements from the end of the list.
|
269 | 260 | [index] > tail
|
270 | 261 | index > idx!
|
271 |
| - ^.origin.length.minus idx.as-number > start! |
| 262 | + origin.length.minus idx > start! |
272 | 263 | if. > @
|
273 | 264 | 0.gt start
|
274 | 265 | ^
|
275 | 266 | list
|
276 |
| - ^.reducedi |
| 267 | + reducedi |
277 | 268 | *
|
278 | 269 | [accum item idx] >>
|
279 | 270 | if. > @
|
280 |
| - idx.gte ^.start |
| 271 | + idx.gte start |
281 | 272 | accum.with item
|
282 | 273 | accum
|
0 commit comments