1 USING: arrays assocs assocs.extras kernel math math.order
5 H{ { 1 V{ 10 } } { 2 V{ 10 } } { 3 V{ 10 } } { 4 V{ 10 } } { 5 V{ 10 } } }
7 H{ } clone 10 { 1 2 3 4 5 } pick push-at-each
10 { f } [ f { } deep-of ] unit-test
11 { f } [ f { "foo" } deep-of ] unit-test
12 { f } [ H{ } { 1 2 3 } deep-of ] unit-test
13 { f } [ H{ { "a" H{ { "b" 1 } } } } { "a" "c" } deep-of ] unit-test
14 { 1 } [ H{ { "a" H{ { "b" 1 } } } } { "a" "b" } deep-of ] unit-test
15 { 4 } [ H{ { 1 H{ { 2 H{ { 3 4 } } } } } } { 1 2 3 } deep-of ] unit-test
17 { H{ { 1 H{ { 2 H{ { 3 44 } } } } } } } [
18 H{ { 1 H{ { 2 H{ { 3 4 } } } } } } dup { 1 2 3 } [ 40 + ] deep-change-of
21 { H{ { 1 H{ { 2 H{ { 3 40 } } } } } } } [
22 H{ { 1 H{ { 2 H{ { 3 4 } } } } } } dup { 1 2 3 } 40 deep-set-of
25 { H{ { 2 1 } { 4 3 } } } [ H{ { 1 2 } { 3 4 } } assoc-invert ] unit-test
27 { H{ { "a" V{ 2 5 } } { "b" V{ 3 } } { "c" V{ 10 } } } }
29 { H{ { "a" 2 } { "b" 3 } } H{ { "a" 5 } { "c" 10 } } }
30 [ ] [ assoc-collect ] map-reduce
33 { H{ } } [ H{ { 1 2 } } 2 over delete-value-at ] unit-test
34 { H{ { 1 2 } } } [ H{ { 1 2 } } 3 over delete-value-at ] unit-test
49 } expand-values-set-at
53 H{ { 1 V{ 3 } } { 2 V{ 3 } } }
65 } expand-values-push-at
69 H{ { 1 [ sq ] } { 2 [ sq ] } }
71 { { { 1 2 { 1 } { 2 } { 1 1 } } [ sq ] } } flatten-keys
75 H{ { "1" 1 } { "2" 2 } }
77 H{ { "1" 1 } { "2" 2 } { "3" 3 } }
83 H{ { "1" 1 } { "2" 2 } { "3" 3 } }
84 [ { "1" "2" "2" } rekey-new-assoc ] keep eq?
88 H{ { "1" 1 } { "2" 2 } }
90 H{ { "1" 1 } { "2" 2 } { "3" 3 } }
96 H{ { "1" 1 } { "2" 2 } { "3" 3 } }
97 [ { "1" "2" "2" } rekey-assoc ] keep eq?
100 { H{ { 1 11 } { 2 22 } { 3 33 } } } [
101 H{ { 1 11 } { 2 20 } }
102 H{ { 2 22 } { 3 33 } }
106 { H{ { 1 11 } { 2 22 } { 3 33 } } } [
107 H{ { 2 22 } { 3 33 } }
108 H{ { 1 11 } { 2 20 } }
112 { H{ { 1 11 } { 2 20 } { 3 33 } } } [
113 H{ { 1 11 } { 2 20 } }
114 H{ { 2 22 } { 3 33 } }
118 { f } [ f f [ min ] assoc-merge ] unit-test
120 ! Ensure non-destructive
122 H{ { 1 11 } { 2 20 } }
123 H{ { 2 22 } { 3 33 } }
124 H{ { 1 11 } { 2 20 } { 3 33 } }
126 H{ { 1 11 } { 2 20 } }
127 H{ { 2 22 } { 3 33 } } 2dup
133 H{ { 1 11 } { 2 20 } { 3 33 } }
134 H{ { 2 22 } { 3 33 } }
135 H{ { 1 11 } { 2 20 } { 3 33 } }
137 H{ { 1 11 } { 2 20 } }
138 H{ { 2 22 } { 3 33 } } 2dup
143 { f } [ f [ min ] assoc-collapse ] unit-test
146 H{ { 1 11 } { 2 20 } }
147 H{ { 1 11 } { 2 20 } { 3 30 } { 4 40 } }
149 H{ { 1 11 } { 2 20 } } dup
150 H{ { 2 22 } { 3 33 } }
151 H{ { 3 30 } { 4 40 } } 3array
152 [ min ] assoc-collapse
156 H{ { 2 22 } { 3 30 } { 4 40 } }
159 H{ { 2 22 } { 3 33 } }
160 H{ { 3 30 } { 4 40 } } 3array
161 [ min ] assoc-collapse
165 H{ { 1 11 } { 2 20 } { 3 30 } { 4 40 } }
167 H{ { 1 11 } { 2 20 } } dup
168 H{ { 2 22 } { 3 33 } }
169 H{ { 3 30 } { 4 40 } } 3array
170 [ min ] assoc-collapse!
174 H{ { 1 11 } { 2 20 } }
175 V{ { 1 11 } { 2 20 } { 3 30 } { 4 40 } }
177 H{ { 1 11 } { 2 20 } } dup
178 H{ { 2 22 } { 3 33 } }
179 H{ { 3 30 } { 4 40 } } 3array
180 [ min ] V{ } assoc-collapse-as
192 { { 10 100 } { 20 200 } { 30 300 } { 41 401 } }
197 H{ { t V{ 100 200 300 } } { f V{ 401 } } }
199 { { 10 100 } { 20 200 } { 30 300 } { 41 401 } }
200 [ [ even? ] dip ] collect-assoc-by
205 { t V{ { 10 100 } { 20 200 } { 30 300 } } }
206 { f V{ { 41 401 } } }
209 { { 10 100 } { 20 200 } { 30 300 } { 41 401 } }
210 [ [ drop even? ] [ 2array ] 2bi ] collect-assoc-by
215 H{ { t V{ 10 21 } } { f V{ 30 41 } } }
217 { { 10 100 } { 21 200 } { 30 301 } { 41 401 } }
218 [ nip even? ] collect-key-by
222 H{ { t V{ 10 30 } } { f V{ 21 41 } } }
224 { { 10 100 } { 21 200 } { 30 301 } { 41 401 } }
225 [ drop even? ] collect-key-by
230 H{ { t V{ 100 200 } } { f V{ 301 401 } } }
232 { { 10 100 } { 21 200 } { 30 301 } { 41 401 } }
233 [ nip even? ] collect-value-by
237 H{ { t V{ 100 301 } } { f V{ 200 401 } } }
239 { { 10 100 } { 21 200 } { 30 301 } { 41 401 } }
240 [ drop even? ] collect-value-by
245 { 1 V{ 10 20 30 40 50 60 } }
246 { 2 V{ 10 20 30 40 50 60 } }
247 { 3 V{ 10 20 30 40 50 60 } }
248 { 4 V{ 10 20 30 40 50 60 } }
249 { 5 V{ 10 20 30 40 50 60 } }
252 { 10 20 30 } [ drop { 1 2 3 4 5 } ] collect-by-multi
253 { 40 50 60 } [ drop { 1 2 3 4 5 } ] collect-by-multi!
270 { { 10 100 } { 20 200 } { 30 300 } { 41 401 } }
271 [ drop dup 1 + 2array ] collect-key-by-multi
287 { { 10 100 } { 20 200 } { 30 300 } { 41 401 } }
288 [ nip dup 1 + 2array ] collect-value-by-multi
304 { { 10 100 } { 20 200 } { 30 300 } { 41 401 } }
305 [ [ dup 1 + 2array ] dip ] collect-assoc-by-multi
308 { H{ { 1 2 } { 3 4 } } } [
309 H{ { 1 2 } { 3 4 } { 5 6 } }
310 { 1 3 } intersect-keys
313 { { { 1 2 } { 3 4 } } } [
314 H{ { 1 2 } { 3 4 } { 5 6 } }
315 { 1 3 } { } intersect-keys-as
320 H{ } clone 1 100 set-of
323 { H{ { 1 V{ 100 200 } } } } [
324 H{ } clone 1 100 push-of 1 200 push-of
327 { H{ { 123 556 } } } [
328 H{ { 123 456 } } 123 [ 100 + ] change-of
331 { H{ { 123 556 } } } [
332 H{ { 123 456 } } 123 [ 100 + ] ?change-of
335 { H{ { 123 456 } } } [
336 H{ { 123 456 } } 1234 [ 100 + ] ?change-of
340 H{ { 10 1 } } 10 inc-of
343 { H{ { 10 1001 } } } [
344 H{ { 10 1 } } 10 1000 of+
347 { H{ { 1 100 } } f } [
348 H{ { 1 100 } } 1 100 maybe-set-of
351 { H{ { 1 100 } { 2 100 } } t } [
352 H{ { 1 100 } } 2 100 maybe-set-of
355 { H{ { 1 100 } } t } [
356 H{ { 1 100 } } 1 101 maybe-set-of