#N canvas 58 52 1154 540 10;
#X floatatom 53 262 5 0 0 0 - - -;
#X msg 42 127 bang;
#X obj 111 262 print TWO_ITEMS;
#X obj 42 292 print RESULT;
#X msg 49 151 1;
#X msg 54 173 1 2;
#X symbolatom 522 188 15 0 0 0 - - -;
#X msg 617 157 \$2-\$1;
#X obj 390 443 u_listreduce;
#X msg 390 416 1 2 3 4 5 6 7 8;
#X msg 485 442 \$2 \$1;
#N canvas 209 220 605 355 more-info 0;
#X msg 84 101 bang;
#X obj 123 237 print TWO_ITEMS;
#X obj 54 266 print RESULT;
#X msg 91 125 1;
#X msg 99 171 1 2 3;
#X msg 96 147 1 2;
#X text 36 42 If nothing is connected to the right inlet \, [u_listreduce]
will act like the left and right outlets of [list split 2] reversed.
;
#X obj 54 203 u_listreduce;
#X msg 342 100 bang;
#X obj 385 244 print TWO_ITEMS;
#X obj 312 265 print RESULT;
#X msg 349 124 1;
#X msg 357 170 1 2 3;
#X msg 354 146 1 2;
#X obj 312 202 list split 2;
#X text 178 202 equal to this:;
#X connect 0 0 7 0;
#X connect 3 0 7 0;
#X connect 4 0 7 0;
#X connect 5 0 7 0;
#X connect 7 0 2 0;
#X connect 7 1 1 0;
#X connect 8 0 14 0;
#X connect 11 0 14 0;
#X connect 12 0 14 0;
#X connect 13 0 14 0;
#X connect 14 0 9 0;
#X connect 14 2 10 0;
#X restore 522 229 pd more-info;
#X obj 390 471 print REVERSE?;
#X obj 522 158 u_listreduce;
#X obj 42 229 u_listreduce;
#X text 529 443 <-- two items == bad idea;
#X msg 522 131 a b c d e;
#X obj 264 211 u_listreduce;
#X obj 357 211 min;
#N canvas 0 22 450 300 randlist 0;
#X obj 254 138 random 100;
#X obj 254 116 until;
#X msg 366 138 set;
#X msg 232 61 10;
#X msg 254 160 add2 \$1;
#X obj 232 88 t b f b;
#X obj 255 236 outlet;
#X obj 232 38 inlet;
#X connect 0 0 4 0;
#X connect 1 0 0 0;
#X connect 2 0 6 0;
#X connect 3 0 5 0;
#X connect 4 0 6 0;
#X connect 5 0 6 0;
#X connect 5 1 1 0;
#X connect 5 2 2 0;
#X connect 7 0 3 0;
#X restore 264 158 pd randlist;
#X msg 264 184 55 82 19 70 97 31 45 65 20 11;
#X msg 264 138 bang;
#X obj 317 237 u_listreduce;
#X floatatom 317 271 5 0 0 3 max - -;
#X obj 411 237 max;
#X floatatom 264 272 5 0 0 3 min - -;
#X obj 131 229 +;
#X obj 46 432 u_listreduce;
#X floatatom 46 455 5 0 0 0 - - -;
#X msg 46 402 22 31 47 86;
#N canvas 0 22 701 458 compare-two 0;
#X obj 99 12 inlet;
#X obj 99 318 outlet;
#X obj 164 162 abs;
#X obj 99 161 abs;
#X obj 99 41 unpack f f;
#X obj 99 90 t a a;
#X obj 99 272 f;
#X obj 164 90 t a a;
#X obj 131 272 f;
#X obj 99 247 select 1 0;
#X text 178 276 send number with smaller distance back to reduce;
#X text 215 151 calculate distances;
#X obj 99 192 <;
#X obj 217 91 inlet;
#X obj 164 139 -;
#X obj 99 138 -;
#X connect 0 0 4 0;
#X connect 2 0 12 1;
#X connect 3 0 12 0;
#X connect 4 0 5 0;
#X connect 4 1 7 0;
#X connect 5 0 15 0;
#X connect 5 1 6 1;
#X connect 6 0 1 0;
#X connect 7 0 14 0;
#X connect 7 1 8 1;
#X connect 8 0 1 0;
#X connect 9 0 6 0;
#X connect 9 1 8 0;
#X connect 12 0 9 0;
#X connect 13 0 14 1;
#X connect 13 0 15 1;
#X connect 14 0 2 0;
#X connect 15 0 3 0;
#X restore 142 432 pd compare-two;
#X floatatom 223 409 5 0 0 0 - - -;
#X msg 223 386 45;
#X obj 223 363 loadbang;
#N canvas 22 203 476 475 REFERENCE 0;
#X text 24 31 Name: u_listreduce;
#X text 24 434 Tags: Message \, Lists;
#X text 24 104 Inlet 0: 'bang' - sends last list again.;
#X text 24 61 Summary: Utility to allow user-defined functions on lists.
;
#X text 24 179 Outlet 0: <list> - result from applied function.;
#X text 24 149 Inlet 1: <list> - return element from function.;
#X text 24 199 Outlet 1: <list> - remainder of input list to apply
to function.;
#X text 24 244 Description: Returns a single value constructed by calling
the user-defined objects connected to the right outlet on the first
two items of the sequence \, then on the result (if it comes in through
the right inlet) and the next item of the original list \, and so on.
If nothing is connected to the right inlet \, [u_listreduce] will act
like the left and right outlets of [list split 2] reversed. Only one
element can be sent back into Inlet 1;
#X text 78 118 <list> - list to apply function to. Single element lists
will pass through unchanged.;
#X text 24 364 See also: [u_list drip] [u_listequal] [u_listfilter]
[u_listloop] [u_listmap] [u_listnth] [u_listrandom] [u_listser];
#X coords 0 -1 1 1 450 450 1 10 10;
#X restore -435 57 pd REFERENCE;
#X obj -435 28 cnv 15 450 20 empty empty empty 20 12 0 14 -261234 -66577
0;
#X text 28 61 Example:;
#X text 389 513 RjDj Library (https://github.com/rjdj/rjlib) - 2011
;
#X obj -432 30 u_listreduce;
#X text 520 108 Merging elements:;
#X text 43 360 Find the closest element:;
#X text -321 31 - Utility to allow user-defined functions on lists
;
#X text 332 367 It's important that there is only one element coming
back in through the right inlet. Lists with more than one item will
be shortened automatically to avoid stack overflows.;
#X text 39 108 Sum elements of list:;
#X msg 57 197 1 2 3 4;
#X text 259 108 Find range of list:;
#X connect 1 0 14 0;
#X connect 4 0 14 0;
#X connect 5 0 14 0;
#X connect 7 0 13 1;
#X connect 8 0 12 0;
#X connect 8 1 10 0;
#X connect 9 0 8 0;
#X connect 10 0 8 1;
#X connect 13 0 6 0;
#X connect 13 1 7 0;
#X connect 14 0 0 0;
#X connect 14 0 3 0;
#X connect 14 1 2 0;
#X connect 14 1 26 0;
#X connect 16 0 13 0;
#X connect 17 0 25 0;
#X connect 17 1 18 0;
#X connect 18 0 17 1;
#X connect 19 0 20 0;
#X connect 20 0 17 0;
#X connect 20 0 22 0;
#X connect 21 0 19 0;
#X connect 22 0 23 0;
#X connect 22 1 24 0;
#X connect 24 0 22 1;
#X connect 26 0 14 1;
#X connect 27 0 28 0;
#X connect 27 1 30 0;
#X connect 29 0 27 0;
#X connect 30 0 27 1;
#X connect 31 0 30 1;
#X connect 32 0 31 0;
#X connect 33 0 32 0;
#X connect 44 0 14 0;
