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-at ] unit-test
10 { f } [ f { "foo" } deep-at ] unit-test
11 { f } [ H{ } { 1 2 3 } deep-at ] unit-test
12 { f } [ H{ { "a" H{ { "b" 1 } } } } { "a" "c" } deep-at ] unit-test
13 { 1 } [ H{ { "a" H{ { "b" 1 } } } } { "a" "b" } deep-at ] unit-test
14 { 4 } [ H{ { 1 H{ { 2 H{ { 3 4 } } } } } } { 1 2 3 } deep-at ] unit-test
16 { H{ { 2 1 } { 4 3 } } } [ H{ { 1 2 } { 3 4 } } assoc-invert ] unit-test
18 { H{ { "a" V{ 2 5 } } { "b" V{ 3 } } { "c" V{ 10 } } } }
20 { H{ { "a" 2 } { "b" 3 } } H{ { "a" 5 } { "c" 10 } } }
21 [ ] [ assoc-collect ] map-reduce
24 { H{ } } [ H{ { 1 2 } } 2 over delete-value-at ] unit-test
25 { H{ { 1 2 } } } [ H{ { 1 2 } } 3 over delete-value-at ] unit-test
40 } expand-values-set-at
44 H{ { 1 V{ 3 } } { 2 V{ 3 } } }
56 } expand-values-push-at
60 H{ { 1 [ sq ] } { 2 [ sq ] } }
62 { { { 1 2 { 1 } { 2 } { 1 1 } } [ sq ] } } flatten-keys
66 H{ { "1" 1 } { "2" 2 } }
68 H{ { "1" 1 } { "2" 2 } { "3" 3 } }
74 H{ { "1" 1 } { "2" 2 } { "3" 3 } }
75 [ { "1" "2" "2" } rekey-new-assoc ] keep eq?
79 H{ { "1" 1 } { "2" 2 } }
81 H{ { "1" 1 } { "2" 2 } { "3" 3 } }
87 H{ { "1" 1 } { "2" 2 } { "3" 3 } }
88 [ { "1" "2" "2" } rekey-assoc ] keep eq?
91 { H{ { 1 11 } { 2 22 } { 3 33 } } } [
92 H{ { 1 11 } { 2 20 } }
93 H{ { 2 22 } { 3 33 } }
97 { H{ { 1 11 } { 2 22 } { 3 33 } } } [
98 H{ { 2 22 } { 3 33 } }
99 H{ { 1 11 } { 2 20 } }
103 { H{ { 1 11 } { 2 20 } { 3 33 } } } [
104 H{ { 1 11 } { 2 20 } }
105 H{ { 2 22 } { 3 33 } }
109 { f } [ f f [ min ] assoc-merge ] unit-test
111 ! Ensure non-destructive
113 H{ { 1 11 } { 2 20 } }
114 H{ { 2 22 } { 3 33 } }
115 H{ { 1 11 } { 2 20 } { 3 33 } }
117 H{ { 1 11 } { 2 20 } }
118 H{ { 2 22 } { 3 33 } } 2dup
124 H{ { 1 11 } { 2 20 } { 3 33 } }
125 H{ { 2 22 } { 3 33 } }
126 H{ { 1 11 } { 2 20 } { 3 33 } }
128 H{ { 1 11 } { 2 20 } }
129 H{ { 2 22 } { 3 33 } } 2dup
134 { f } [ f [ min ] assoc-collapse ] unit-test
137 H{ { 1 11 } { 2 20 } }
138 H{ { 1 11 } { 2 20 } { 3 30 } { 4 40 } }
140 H{ { 1 11 } { 2 20 } } dup
141 H{ { 2 22 } { 3 33 } }
142 H{ { 3 30 } { 4 40 } } 3array
143 [ min ] assoc-collapse
147 H{ { 2 22 } { 3 30 } { 4 40 } }
150 H{ { 2 22 } { 3 33 } }
151 H{ { 3 30 } { 4 40 } } 3array
152 [ min ] assoc-collapse
156 H{ { 1 11 } { 2 20 } { 3 30 } { 4 40 } }
158 H{ { 1 11 } { 2 20 } } dup
159 H{ { 2 22 } { 3 33 } }
160 H{ { 3 30 } { 4 40 } } 3array
161 [ min ] assoc-collapse!
165 H{ { 1 11 } { 2 20 } }
166 V{ { 1 11 } { 2 20 } { 3 30 } { 4 40 } }
168 H{ { 1 11 } { 2 20 } } dup
169 H{ { 2 22 } { 3 33 } }
170 H{ { 3 30 } { 4 40 } } 3array
171 [ min ] V{ } assoc-collapse-as
183 { { 10 100 } { 20 200 } { 30 300 } { 41 401 } }
188 H{ { t V{ 100 200 300 } } { f V{ 401 } } }
190 { { 10 100 } { 20 200 } { 30 300 } { 41 401 } }
191 [ [ even? ] dip ] collect-assoc-by
196 { t V{ { 10 100 } { 20 200 } { 30 300 } } }
197 { f V{ { 41 401 } } }
200 { { 10 100 } { 20 200 } { 30 300 } { 41 401 } }
201 [ [ drop even? ] [ 2array ] 2bi ] collect-assoc-by
205 H{ { t V{ 10 20 30 } } { f V{ 41 } } }
207 { { 10 100 } { 20 200 } { 30 300 } { 41 401 } }
208 [ even? ] collect-key-by
212 H{ { t V{ 100 200 300 } } { f V{ 401 } } }
214 { { 10 100 } { 20 200 } { 30 300 } { 41 401 } }
215 [ even? ] collect-value-by
221 { 1 V{ 10 20 30 40 50 60 } }
222 { 2 V{ 10 20 30 40 50 60 } }
223 { 3 V{ 10 20 30 40 50 60 } }
224 { 4 V{ 10 20 30 40 50 60 } }
225 { 5 V{ 10 20 30 40 50 60 } }
228 { 10 20 30 } [ drop { 1 2 3 4 5 } ] collect-by-multi
229 { 40 50 60 } [ drop { 1 2 3 4 5 } ] collect-by-multi!
246 { { 10 100 } { 20 200 } { 30 300 } { 41 401 } }
247 [ dup 1 + 2array ] collect-key-by-multi
263 { { 10 100 } { 20 200 } { 30 300 } { 41 401 } }
264 [ dup 1 + 2array ] collect-value-by-multi
280 { { 10 100 } { 20 200 } { 30 300 } { 41 401 } }
281 [ [ dup 1 + 2array ] dip ] collect-assoc-by-multi