1 USING: arrays assocs.extras kernel math math.order sequences tools.test ;
4 H{ { 1 V{ 10 } } { 2 V{ 10 } } { 3 V{ 10 } } { 4 V{ 10 } } { 5 V{ 10 } } }
6 H{ } clone 10 { 1 2 3 4 5 } pick push-at-each
9 { f } [ f { } deep-of ] unit-test
10 { f } [ f { "foo" } deep-of ] unit-test
11 { f } [ H{ } { 1 2 3 } deep-of ] unit-test
12 { f } [ H{ { "a" H{ { "b" 1 } } } } { "a" "c" } deep-of ] unit-test
13 { 1 } [ H{ { "a" H{ { "b" 1 } } } } { "a" "b" } deep-of ] unit-test
14 { 4 } [ H{ { 1 H{ { 2 H{ { 3 4 } } } } } } { 1 2 3 } deep-of ] unit-test
16 { H{ { 1 H{ { 2 H{ { 3 44 } } } } } } } [
17 H{ { 1 H{ { 2 H{ { 3 4 } } } } } } dup { 1 2 3 } [ 40 + ] deep-change-of
20 { H{ { 1 H{ { 2 H{ { 3 40 } } } } } } } [
21 H{ { 1 H{ { 2 H{ { 3 4 } } } } } } dup { 1 2 3 } 40 deep-set-of
24 { { { 1 1 } { 2 2 } { 0 3 } { 0 4 } { 0 5 } } } [
25 { 1 2 } { 1 2 3 4 5 } 0 zip-longest-with
28 { { { 1 1 } { 2 2 } { f 3 } { f 4 } { f 5 } } } [
29 { 1 2 } { 1 2 3 4 5 } zip-longest
32 { H{ { 2 1 } { 4 3 } } } [ H{ { 1 2 } { 3 4 } } assoc-invert ] unit-test
34 { H{ { "a" V{ 2 5 } } { "b" V{ 3 } } { "c" V{ 10 } } } }
36 { H{ { "a" 2 } { "b" 3 } } H{ { "a" 5 } { "c" 10 } } }
37 [ ] [ assoc-collect ] map-reduce
40 { H{ } } [ H{ { 1 2 } } 2 over delete-value-at ] unit-test
41 { H{ { 1 2 } } } [ H{ { 1 2 } } 3 over delete-value-at ] unit-test
56 } expand-values-set-at
60 H{ { 1 V{ 3 } } { 2 V{ 3 } } }
72 } expand-values-push-at
76 H{ { 1 [ sq ] } { 2 [ sq ] } }
78 { { { 1 2 { 1 } { 2 } { 1 1 } } [ sq ] } } flatten-keys
82 H{ { "1" 1 } { "2" 2 } }
84 H{ { "1" 1 } { "2" 2 } { "3" 3 } }
90 H{ { "1" 1 } { "2" 2 } { "3" 3 } }
91 [ { "1" "2" "2" } rekey-new-assoc ] keep eq?
95 H{ { "1" 1 } { "2" 2 } }
97 H{ { "1" 1 } { "2" 2 } { "3" 3 } }
103 H{ { "1" 1 } { "2" 2 } { "3" 3 } }
104 [ { "1" "2" "2" } rekey-assoc ] keep eq?
107 { H{ { 1 11 } { 2 22 } { 3 33 } } } [
108 H{ { 1 11 } { 2 20 } }
109 H{ { 2 22 } { 3 33 } }
113 { H{ { 1 11 } { 2 22 } { 3 33 } } } [
114 H{ { 2 22 } { 3 33 } }
115 H{ { 1 11 } { 2 20 } }
119 { H{ { 1 11 } { 2 20 } { 3 33 } } } [
120 H{ { 1 11 } { 2 20 } }
121 H{ { 2 22 } { 3 33 } }
125 { f } [ f f [ min ] assoc-merge ] unit-test
127 ! Ensure non-destructive
129 H{ { 1 11 } { 2 20 } }
130 H{ { 2 22 } { 3 33 } }
131 H{ { 1 11 } { 2 20 } { 3 33 } }
133 H{ { 1 11 } { 2 20 } }
134 H{ { 2 22 } { 3 33 } } 2dup
140 H{ { 1 11 } { 2 20 } { 3 33 } }
141 H{ { 2 22 } { 3 33 } }
142 H{ { 1 11 } { 2 20 } { 3 33 } }
144 H{ { 1 11 } { 2 20 } }
145 H{ { 2 22 } { 3 33 } } 2dup
150 { f } [ f [ min ] assoc-collapse ] unit-test
153 H{ { 1 11 } { 2 20 } }
154 H{ { 1 11 } { 2 20 } { 3 30 } { 4 40 } }
156 H{ { 1 11 } { 2 20 } } dup
157 H{ { 2 22 } { 3 33 } }
158 H{ { 3 30 } { 4 40 } } 3array
159 [ min ] assoc-collapse
163 H{ { 2 22 } { 3 30 } { 4 40 } }
166 H{ { 2 22 } { 3 33 } }
167 H{ { 3 30 } { 4 40 } } 3array
168 [ min ] assoc-collapse
172 H{ { 1 11 } { 2 20 } { 3 30 } { 4 40 } }
174 H{ { 1 11 } { 2 20 } } dup
175 H{ { 2 22 } { 3 33 } }
176 H{ { 3 30 } { 4 40 } } 3array
177 [ min ] assoc-collapse!
181 H{ { 1 11 } { 2 20 } }
182 V{ { 1 11 } { 2 20 } { 3 30 } { 4 40 } }
184 H{ { 1 11 } { 2 20 } } dup
185 H{ { 2 22 } { 3 33 } }
186 H{ { 3 30 } { 4 40 } } 3array
187 [ min ] V{ } assoc-collapse-as
199 { { 10 100 } { 20 200 } { 30 300 } { 41 401 } }
204 H{ { t V{ 100 200 300 } } { f V{ 401 } } }
206 { { 10 100 } { 20 200 } { 30 300 } { 41 401 } }
207 [ [ even? ] dip ] collect-assoc-by
212 { t V{ { 10 100 } { 20 200 } { 30 300 } } }
213 { f V{ { 41 401 } } }
216 { { 10 100 } { 20 200 } { 30 300 } { 41 401 } }
217 [ [ drop even? ] [ 2array ] 2bi ] collect-assoc-by
222 H{ { t V{ 10 21 } } { f V{ 30 41 } } }
224 { { 10 100 } { 21 200 } { 30 301 } { 41 401 } }
225 [ nip even? ] collect-key-by
229 H{ { t V{ 10 30 } } { f V{ 21 41 } } }
231 { { 10 100 } { 21 200 } { 30 301 } { 41 401 } }
232 [ drop even? ] collect-key-by
237 H{ { t V{ 100 200 } } { f V{ 301 401 } } }
239 { { 10 100 } { 21 200 } { 30 301 } { 41 401 } }
240 [ nip even? ] collect-value-by
244 H{ { t V{ 100 301 } } { f V{ 200 401 } } }
246 { { 10 100 } { 21 200 } { 30 301 } { 41 401 } }
247 [ drop even? ] collect-value-by
252 { 1 V{ 10 20 30 40 50 60 } }
253 { 2 V{ 10 20 30 40 50 60 } }
254 { 3 V{ 10 20 30 40 50 60 } }
255 { 4 V{ 10 20 30 40 50 60 } }
256 { 5 V{ 10 20 30 40 50 60 } }
259 { 10 20 30 } [ drop { 1 2 3 4 5 } ] collect-by-multi
260 { 40 50 60 } [ drop { 1 2 3 4 5 } ] collect-by-multi!
277 { { 10 100 } { 20 200 } { 30 300 } { 41 401 } }
278 [ drop dup 1 + 2array ] collect-key-by-multi
294 { { 10 100 } { 20 200 } { 30 300 } { 41 401 } }
295 [ nip dup 1 + 2array ] collect-value-by-multi
311 { { 10 100 } { 20 200 } { 30 300 } { 41 401 } }
312 [ [ dup 1 + 2array ] dip ] collect-assoc-by-multi
315 { H{ { 1 2 } { 3 4 } } } [
316 H{ { 1 2 } { 3 4 } { 5 6 } }
317 { 1 3 } intersect-keys
320 { { { 1 2 } { 3 4 } } } [
321 H{ { 1 2 } { 3 4 } { 5 6 } }
322 { 1 3 } { } intersect-keys-as