1 USING: arrays assocs.extras kernel math math.order sequences tools.test ;
3 { f } [ f { } deep-at ] unit-test
4 { f } [ f { "foo" } deep-at ] unit-test
5 { f } [ H{ } { 1 2 3 } deep-at ] unit-test
6 { f } [ H{ { "a" H{ { "b" 1 } } } } { "a" "c" } deep-at ] unit-test
7 { 1 } [ H{ { "a" H{ { "b" 1 } } } } { "a" "b" } deep-at ] unit-test
8 { 4 } [ H{ { 1 H{ { 2 H{ { 3 4 } } } } } } { 1 2 3 } deep-at ] unit-test
10 { H{ { 2 1 } { 4 3 } } } [ H{ { 1 2 } { 3 4 } } assoc-invert ] unit-test
12 { H{ { "a" V{ 2 5 } } { "b" V{ 3 } } { "c" V{ 10 } } } }
14 { H{ { "a" 2 } { "b" 3 } } H{ { "a" 5 } { "c" 10 } } }
15 [ ] [ assoc-collect ] map-reduce
18 { H{ } } [ H{ { 1 2 } } 2 over delete-value-at ] unit-test
19 { H{ { 1 2 } } } [ H{ { 1 2 } } 3 over delete-value-at ] unit-test
34 } expand-values-set-at
38 H{ { 1 V{ 3 } } { 2 V{ 3 } } }
50 } expand-values-push-at
54 H{ { 1 [ sq ] } { 2 [ sq ] } }
56 { { { 1 2 { 1 } { 2 } { 1 1 } } [ sq ] } } flatten-keys
60 H{ { "1" 1 } { "2" 2 } }
62 H{ { "1" 1 } { "2" 2 } { "3" 3 } }
68 H{ { "1" 1 } { "2" 2 } { "3" 3 } }
69 [ { "1" "2" "2" } rekey-new-assoc ] keep eq?
73 H{ { "1" 1 } { "2" 2 } }
75 H{ { "1" 1 } { "2" 2 } { "3" 3 } }
81 H{ { "1" 1 } { "2" 2 } { "3" 3 } }
82 [ { "1" "2" "2" } rekey-assoc ] keep eq?
85 { H{ { 1 11 } { 2 22 } { 3 33 } } } [
86 H{ { 1 11 } { 2 20 } }
87 H{ { 2 22 } { 3 33 } }
91 { H{ { 1 11 } { 2 22 } { 3 33 } } } [
92 H{ { 2 22 } { 3 33 } }
93 H{ { 1 11 } { 2 20 } }
97 { H{ { 1 11 } { 2 20 } { 3 33 } } } [
98 H{ { 1 11 } { 2 20 } }
99 H{ { 2 22 } { 3 33 } }
103 { f } [ f f [ min ] assoc-merge ] unit-test
105 ! Ensure non-destructive
107 H{ { 1 11 } { 2 20 } }
108 H{ { 2 22 } { 3 33 } }
109 H{ { 1 11 } { 2 20 } { 3 33 } }
111 H{ { 1 11 } { 2 20 } }
112 H{ { 2 22 } { 3 33 } } 2dup
118 H{ { 1 11 } { 2 20 } { 3 33 } }
119 H{ { 2 22 } { 3 33 } }
120 H{ { 1 11 } { 2 20 } { 3 33 } }
122 H{ { 1 11 } { 2 20 } }
123 H{ { 2 22 } { 3 33 } } 2dup
128 { f } [ f [ min ] assoc-collapse ] unit-test
131 H{ { 1 11 } { 2 20 } }
132 H{ { 1 11 } { 2 20 } { 3 30 } { 4 40 } }
134 H{ { 1 11 } { 2 20 } } dup
135 H{ { 2 22 } { 3 33 } }
136 H{ { 3 30 } { 4 40 } } 3array
137 [ min ] assoc-collapse
141 H{ { 2 22 } { 3 30 } { 4 40 } }
144 H{ { 2 22 } { 3 33 } }
145 H{ { 3 30 } { 4 40 } } 3array
146 [ min ] assoc-collapse
150 H{ { 1 11 } { 2 20 } { 3 30 } { 4 40 } }
152 H{ { 1 11 } { 2 20 } } dup
153 H{ { 2 22 } { 3 33 } }
154 H{ { 3 30 } { 4 40 } } 3array
155 [ min ] assoc-collapse!
159 H{ { 1 11 } { 2 20 } }
160 V{ { 1 11 } { 2 20 } { 3 30 } { 4 40 } }
162 H{ { 1 11 } { 2 20 } } dup
163 H{ { 2 22 } { 3 33 } }
164 H{ { 3 30 } { 4 40 } } 3array
165 [ min ] V{ } assoc-collapse-as
169 H{ { 1 V{ 10 } } { 2 V{ 10 } } { 3 V{ 10 } } { 4 V{ 10 } } { 5 V{ 10 } } }
171 H{ } clone 10 { 1 2 3 4 5 } pick push-at-each
176 { 1 V{ 10 20 30 40 50 60 } }
177 { 2 V{ 10 20 30 40 50 60 } }
178 { 3 V{ 10 20 30 40 50 60 } }
179 { 4 V{ 10 20 30 40 50 60 } }
180 { 5 V{ 10 20 30 40 50 60 } }
183 { 10 20 30 } [ drop { 1 2 3 4 5 } ] collect-by-multi
184 { 40 50 60 } [ drop { 1 2 3 4 5 } ] collect-by-multi!