Iter.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  1. /***
  2. MochiKit.Iter 1.4
  3. See <http://mochikit.com/> for documentation, downloads, license, etc.
  4. (c) 2005 Bob Ippolito. All rights Reserved.
  5. ***/
  6. if (typeof(dojo) != 'undefined') {
  7. dojo.provide('MochiKit.Iter');
  8. dojo.require('MochiKit.Base');
  9. }
  10. if (typeof(JSAN) != 'undefined') {
  11. JSAN.use("MochiKit.Base", []);
  12. }
  13. try {
  14. if (typeof(MochiKit.Base) == 'undefined') {
  15. throw "";
  16. }
  17. } catch (e) {
  18. throw "MochiKit.Iter depends on MochiKit.Base!";
  19. }
  20. if (typeof(MochiKit.Iter) == 'undefined') {
  21. MochiKit.Iter = {};
  22. }
  23. MochiKit.Iter.NAME = "MochiKit.Iter";
  24. MochiKit.Iter.VERSION = "1.4";
  25. MochiKit.Base.update(MochiKit.Iter, {
  26. __repr__: function () {
  27. return "[" + this.NAME + " " + this.VERSION + "]";
  28. },
  29. toString: function () {
  30. return this.__repr__();
  31. },
  32. /** @id MochiKit.Iter.registerIteratorFactory */
  33. registerIteratorFactory: function (name, check, iterfactory, /* optional */ override) {
  34. MochiKit.Iter.iteratorRegistry.register(name, check, iterfactory, override);
  35. },
  36. /** @id MochiKit.Iter.iter */
  37. iter: function (iterable, /* optional */ sentinel) {
  38. var self = MochiKit.Iter;
  39. if (arguments.length == 2) {
  40. return self.takewhile(
  41. function (a) { return a != sentinel; },
  42. iterable
  43. );
  44. }
  45. if (typeof(iterable.next) == 'function') {
  46. return iterable;
  47. } else if (typeof(iterable.iter) == 'function') {
  48. return iterable.iter();
  49. /*
  50. } else if (typeof(iterable.__iterator__) == 'function') {
  51. //
  52. // XXX: We can't support JavaScript 1.7 __iterator__ directly
  53. // because of Object.prototype.__iterator__
  54. //
  55. return iterable.__iterator__();
  56. */
  57. }
  58. try {
  59. return self.iteratorRegistry.match(iterable);
  60. } catch (e) {
  61. var m = MochiKit.Base;
  62. if (e == m.NotFound) {
  63. e = new TypeError(typeof(iterable) + ": " + m.repr(iterable) + " is not iterable");
  64. }
  65. throw e;
  66. }
  67. },
  68. /** @id MochiKit.Iter.count */
  69. count: function (n) {
  70. if (!n) {
  71. n = 0;
  72. }
  73. var m = MochiKit.Base;
  74. return {
  75. repr: function () { return "count(" + n + ")"; },
  76. toString: m.forwardCall("repr"),
  77. next: m.counter(n)
  78. };
  79. },
  80. /** @id MochiKit.Iter.cycle */
  81. cycle: function (p) {
  82. var self = MochiKit.Iter;
  83. var m = MochiKit.Base;
  84. var lst = [];
  85. var iterator = self.iter(p);
  86. return {
  87. repr: function () { return "cycle(...)"; },
  88. toString: m.forwardCall("repr"),
  89. next: function () {
  90. try {
  91. var rval = iterator.next();
  92. lst.push(rval);
  93. return rval;
  94. } catch (e) {
  95. if (e != self.StopIteration) {
  96. throw e;
  97. }
  98. if (lst.length === 0) {
  99. this.next = function () {
  100. throw self.StopIteration;
  101. };
  102. } else {
  103. var i = -1;
  104. this.next = function () {
  105. i = (i + 1) % lst.length;
  106. return lst[i];
  107. };
  108. }
  109. return this.next();
  110. }
  111. }
  112. };
  113. },
  114. /** @id MochiKit.Iter.repeat */
  115. repeat: function (elem, /* optional */n) {
  116. var m = MochiKit.Base;
  117. if (typeof(n) == 'undefined') {
  118. return {
  119. repr: function () {
  120. return "repeat(" + m.repr(elem) + ")";
  121. },
  122. toString: m.forwardCall("repr"),
  123. next: function () {
  124. return elem;
  125. }
  126. };
  127. }
  128. return {
  129. repr: function () {
  130. return "repeat(" + m.repr(elem) + ", " + n + ")";
  131. },
  132. toString: m.forwardCall("repr"),
  133. next: function () {
  134. if (n <= 0) {
  135. throw MochiKit.Iter.StopIteration;
  136. }
  137. n -= 1;
  138. return elem;
  139. }
  140. };
  141. },
  142. /** @id MochiKit.Iter.next */
  143. next: function (iterator) {
  144. return iterator.next();
  145. },
  146. /** @id MochiKit.Iter.izip */
  147. izip: function (p, q/*, ...*/) {
  148. var m = MochiKit.Base;
  149. var self = MochiKit.Iter;
  150. var next = self.next;
  151. var iterables = m.map(self.iter, arguments);
  152. return {
  153. repr: function () { return "izip(...)"; },
  154. toString: m.forwardCall("repr"),
  155. next: function () { return m.map(next, iterables); }
  156. };
  157. },
  158. /** @id MochiKit.Iter.ifilter */
  159. ifilter: function (pred, seq) {
  160. var m = MochiKit.Base;
  161. seq = MochiKit.Iter.iter(seq);
  162. if (pred === null) {
  163. pred = m.operator.truth;
  164. }
  165. return {
  166. repr: function () { return "ifilter(...)"; },
  167. toString: m.forwardCall("repr"),
  168. next: function () {
  169. while (true) {
  170. var rval = seq.next();
  171. if (pred(rval)) {
  172. return rval;
  173. }
  174. }
  175. // mozilla warnings aren't too bright
  176. return undefined;
  177. }
  178. };
  179. },
  180. /** @id MochiKit.Iter.ifilterfalse */
  181. ifilterfalse: function (pred, seq) {
  182. var m = MochiKit.Base;
  183. seq = MochiKit.Iter.iter(seq);
  184. if (pred === null) {
  185. pred = m.operator.truth;
  186. }
  187. return {
  188. repr: function () { return "ifilterfalse(...)"; },
  189. toString: m.forwardCall("repr"),
  190. next: function () {
  191. while (true) {
  192. var rval = seq.next();
  193. if (!pred(rval)) {
  194. return rval;
  195. }
  196. }
  197. // mozilla warnings aren't too bright
  198. return undefined;
  199. }
  200. };
  201. },
  202. /** @id MochiKit.Iter.islice */
  203. islice: function (seq/*, [start,] stop[, step] */) {
  204. var self = MochiKit.Iter;
  205. var m = MochiKit.Base;
  206. seq = self.iter(seq);
  207. var start = 0;
  208. var stop = 0;
  209. var step = 1;
  210. var i = -1;
  211. if (arguments.length == 2) {
  212. stop = arguments[1];
  213. } else if (arguments.length == 3) {
  214. start = arguments[1];
  215. stop = arguments[2];
  216. } else {
  217. start = arguments[1];
  218. stop = arguments[2];
  219. step = arguments[3];
  220. }
  221. return {
  222. repr: function () {
  223. return "islice(" + ["...", start, stop, step].join(", ") + ")";
  224. },
  225. toString: m.forwardCall("repr"),
  226. next: function () {
  227. var rval;
  228. while (i < start) {
  229. rval = seq.next();
  230. i++;
  231. }
  232. if (start >= stop) {
  233. throw self.StopIteration;
  234. }
  235. start += step;
  236. return rval;
  237. }
  238. };
  239. },
  240. /** @id MochiKit.Iter.imap */
  241. imap: function (fun, p, q/*, ...*/) {
  242. var m = MochiKit.Base;
  243. var self = MochiKit.Iter;
  244. var iterables = m.map(self.iter, m.extend(null, arguments, 1));
  245. var map = m.map;
  246. var next = self.next;
  247. return {
  248. repr: function () { return "imap(...)"; },
  249. toString: m.forwardCall("repr"),
  250. next: function () {
  251. return fun.apply(this, map(next, iterables));
  252. }
  253. };
  254. },
  255. /** @id MochiKit.Iter.applymap */
  256. applymap: function (fun, seq, self) {
  257. seq = MochiKit.Iter.iter(seq);
  258. var m = MochiKit.Base;
  259. return {
  260. repr: function () { return "applymap(...)"; },
  261. toString: m.forwardCall("repr"),
  262. next: function () {
  263. return fun.apply(self, seq.next());
  264. }
  265. };
  266. },
  267. /** @id MochiKit.Iter.chain */
  268. chain: function (p, q/*, ...*/) {
  269. // dumb fast path
  270. var self = MochiKit.Iter;
  271. var m = MochiKit.Base;
  272. if (arguments.length == 1) {
  273. return self.iter(arguments[0]);
  274. }
  275. var argiter = m.map(self.iter, arguments);
  276. return {
  277. repr: function () { return "chain(...)"; },
  278. toString: m.forwardCall("repr"),
  279. next: function () {
  280. while (argiter.length > 1) {
  281. try {
  282. return argiter[0].next();
  283. } catch (e) {
  284. if (e != self.StopIteration) {
  285. throw e;
  286. }
  287. argiter.shift();
  288. }
  289. }
  290. if (argiter.length == 1) {
  291. // optimize last element
  292. var arg = argiter.shift();
  293. this.next = m.bind("next", arg);
  294. return this.next();
  295. }
  296. throw self.StopIteration;
  297. }
  298. };
  299. },
  300. /** @id MochiKit.Iter.takewhile */
  301. takewhile: function (pred, seq) {
  302. var self = MochiKit.Iter;
  303. seq = self.iter(seq);
  304. return {
  305. repr: function () { return "takewhile(...)"; },
  306. toString: MochiKit.Base.forwardCall("repr"),
  307. next: function () {
  308. var rval = seq.next();
  309. if (!pred(rval)) {
  310. this.next = function () {
  311. throw self.StopIteration;
  312. };
  313. this.next();
  314. }
  315. return rval;
  316. }
  317. };
  318. },
  319. /** @id MochiKit.Iter.dropwhile */
  320. dropwhile: function (pred, seq) {
  321. seq = MochiKit.Iter.iter(seq);
  322. var m = MochiKit.Base;
  323. var bind = m.bind;
  324. return {
  325. "repr": function () { return "dropwhile(...)"; },
  326. "toString": m.forwardCall("repr"),
  327. "next": function () {
  328. while (true) {
  329. var rval = seq.next();
  330. if (!pred(rval)) {
  331. break;
  332. }
  333. }
  334. this.next = bind("next", seq);
  335. return rval;
  336. }
  337. };
  338. },
  339. _tee: function (ident, sync, iterable) {
  340. sync.pos[ident] = -1;
  341. var m = MochiKit.Base;
  342. var listMin = m.listMin;
  343. return {
  344. repr: function () { return "tee(" + ident + ", ...)"; },
  345. toString: m.forwardCall("repr"),
  346. next: function () {
  347. var rval;
  348. var i = sync.pos[ident];
  349. if (i == sync.max) {
  350. rval = iterable.next();
  351. sync.deque.push(rval);
  352. sync.max += 1;
  353. sync.pos[ident] += 1;
  354. } else {
  355. rval = sync.deque[i - sync.min];
  356. sync.pos[ident] += 1;
  357. if (i == sync.min && listMin(sync.pos) != sync.min) {
  358. sync.min += 1;
  359. sync.deque.shift();
  360. }
  361. }
  362. return rval;
  363. }
  364. };
  365. },
  366. /** @id MochiKit.Iter.tee */
  367. tee: function (iterable, n/* = 2 */) {
  368. var rval = [];
  369. var sync = {
  370. "pos": [],
  371. "deque": [],
  372. "max": -1,
  373. "min": -1
  374. };
  375. if (arguments.length == 1 || typeof(n) == "undefined" || n === null) {
  376. n = 2;
  377. }
  378. var self = MochiKit.Iter;
  379. iterable = self.iter(iterable);
  380. var _tee = self._tee;
  381. for (var i = 0; i < n; i++) {
  382. rval.push(_tee(i, sync, iterable));
  383. }
  384. return rval;
  385. },
  386. /** @id MochiKit.Iter.list */
  387. list: function (iterable) {
  388. // Fast-path for Array and Array-like
  389. var m = MochiKit.Base;
  390. if (typeof(iterable.slice) == 'function') {
  391. return iterable.slice();
  392. } else if (m.isArrayLike(iterable)) {
  393. return m.concat(iterable);
  394. }
  395. var self = MochiKit.Iter;
  396. iterable = self.iter(iterable);
  397. var rval = [];
  398. try {
  399. while (true) {
  400. rval.push(iterable.next());
  401. }
  402. } catch (e) {
  403. if (e != self.StopIteration) {
  404. throw e;
  405. }
  406. return rval;
  407. }
  408. // mozilla warnings aren't too bright
  409. return undefined;
  410. },
  411. /** @id MochiKit.Iter.reduce */
  412. reduce: function (fn, iterable, /* optional */initial) {
  413. var i = 0;
  414. var x = initial;
  415. var self = MochiKit.Iter;
  416. iterable = self.iter(iterable);
  417. if (arguments.length < 3) {
  418. try {
  419. x = iterable.next();
  420. } catch (e) {
  421. if (e == self.StopIteration) {
  422. e = new TypeError("reduce() of empty sequence with no initial value");
  423. }
  424. throw e;
  425. }
  426. i++;
  427. }
  428. try {
  429. while (true) {
  430. x = fn(x, iterable.next());
  431. }
  432. } catch (e) {
  433. if (e != self.StopIteration) {
  434. throw e;
  435. }
  436. }
  437. return x;
  438. },
  439. /** @id MochiKit.Iter.range */
  440. range: function (/* [start,] stop[, step] */) {
  441. var start = 0;
  442. var stop = 0;
  443. var step = 1;
  444. if (arguments.length == 1) {
  445. stop = arguments[0];
  446. } else if (arguments.length == 2) {
  447. start = arguments[0];
  448. stop = arguments[1];
  449. } else if (arguments.length == 3) {
  450. start = arguments[0];
  451. stop = arguments[1];
  452. step = arguments[2];
  453. } else {
  454. throw new TypeError("range() takes 1, 2, or 3 arguments!");
  455. }
  456. if (step === 0) {
  457. throw new TypeError("range() step must not be 0");
  458. }
  459. return {
  460. next: function () {
  461. if ((step > 0 && start >= stop) || (step < 0 && start <= stop)) {
  462. throw MochiKit.Iter.StopIteration;
  463. }
  464. var rval = start;
  465. start += step;
  466. return rval;
  467. },
  468. repr: function () {
  469. return "range(" + [start, stop, step].join(", ") + ")";
  470. },
  471. toString: MochiKit.Base.forwardCall("repr")
  472. };
  473. },
  474. /** @id MochiKit.Iter.sum */
  475. sum: function (iterable, start/* = 0 */) {
  476. if (typeof(start) == "undefined" || start === null) {
  477. start = 0;
  478. }
  479. var x = start;
  480. var self = MochiKit.Iter;
  481. iterable = self.iter(iterable);
  482. try {
  483. while (true) {
  484. x += iterable.next();
  485. }
  486. } catch (e) {
  487. if (e != self.StopIteration) {
  488. throw e;
  489. }
  490. }
  491. return x;
  492. },
  493. /** @id MochiKit.Iter.exhaust */
  494. exhaust: function (iterable) {
  495. var self = MochiKit.Iter;
  496. iterable = self.iter(iterable);
  497. try {
  498. while (true) {
  499. iterable.next();
  500. }
  501. } catch (e) {
  502. if (e != self.StopIteration) {
  503. throw e;
  504. }
  505. }
  506. },
  507. /** @id MochiKit.Iter.forEach */
  508. forEach: function (iterable, func, /* optional */self) {
  509. var m = MochiKit.Base;
  510. if (arguments.length > 2) {
  511. func = m.bind(func, self);
  512. }
  513. // fast path for array
  514. if (m.isArrayLike(iterable)) {
  515. try {
  516. for (var i = 0; i < iterable.length; i++) {
  517. func(iterable[i]);
  518. }
  519. } catch (e) {
  520. if (e != MochiKit.Iter.StopIteration) {
  521. throw e;
  522. }
  523. }
  524. } else {
  525. self = MochiKit.Iter;
  526. self.exhaust(self.imap(func, iterable));
  527. }
  528. },
  529. /** @id MochiKit.Iter.every */
  530. every: function (iterable, func) {
  531. var self = MochiKit.Iter;
  532. try {
  533. self.ifilterfalse(func, iterable).next();
  534. return false;
  535. } catch (e) {
  536. if (e != self.StopIteration) {
  537. throw e;
  538. }
  539. return true;
  540. }
  541. },
  542. /** @id MochiKit.Iter.sorted */
  543. sorted: function (iterable, /* optional */cmp) {
  544. var rval = MochiKit.Iter.list(iterable);
  545. if (arguments.length == 1) {
  546. cmp = MochiKit.Base.compare;
  547. }
  548. rval.sort(cmp);
  549. return rval;
  550. },
  551. /** @id MochiKit.Iter.reversed */
  552. reversed: function (iterable) {
  553. var rval = MochiKit.Iter.list(iterable);
  554. rval.reverse();
  555. return rval;
  556. },
  557. /** @id MochiKit.Iter.some */
  558. some: function (iterable, func) {
  559. var self = MochiKit.Iter;
  560. try {
  561. self.ifilter(func, iterable).next();
  562. return true;
  563. } catch (e) {
  564. if (e != self.StopIteration) {
  565. throw e;
  566. }
  567. return false;
  568. }
  569. },
  570. /** @id MochiKit.Iter.iextend */
  571. iextend: function (lst, iterable) {
  572. if (MochiKit.Base.isArrayLike(iterable)) {
  573. // fast-path for array-like
  574. for (var i = 0; i < iterable.length; i++) {
  575. lst.push(iterable[i]);
  576. }
  577. } else {
  578. var self = MochiKit.Iter;
  579. iterable = self.iter(iterable);
  580. try {
  581. while (true) {
  582. lst.push(iterable.next());
  583. }
  584. } catch (e) {
  585. if (e != self.StopIteration) {
  586. throw e;
  587. }
  588. }
  589. }
  590. return lst;
  591. },
  592. /** @id MochiKit.Iter.groupby */
  593. groupby: function(iterable, /* optional */ keyfunc) {
  594. var m = MochiKit.Base;
  595. var self = MochiKit.Iter;
  596. if (arguments.length < 2) {
  597. keyfunc = m.operator.identity;
  598. }
  599. iterable = self.iter(iterable);
  600. // shared
  601. var pk = undefined;
  602. var k = undefined;
  603. var v;
  604. function fetch() {
  605. v = iterable.next();
  606. k = keyfunc(v);
  607. };
  608. function eat() {
  609. var ret = v;
  610. v = undefined;
  611. return ret;
  612. };
  613. var first = true;
  614. var compare = m.compare;
  615. return {
  616. repr: function () { return "groupby(...)"; },
  617. next: function() {
  618. // iterator-next
  619. // iterate until meet next group
  620. while (compare(k, pk) === 0) {
  621. fetch();
  622. if (first) {
  623. first = false;
  624. break;
  625. }
  626. }
  627. pk = k;
  628. return [k, {
  629. next: function() {
  630. // subiterator-next
  631. if (v == undefined) { // Is there something to eat?
  632. fetch();
  633. }
  634. if (compare(k, pk) !== 0) {
  635. throw self.StopIteration;
  636. }
  637. return eat();
  638. }
  639. }];
  640. }
  641. };
  642. },
  643. /** @id MochiKit.Iter.groupby_as_array */
  644. groupby_as_array: function (iterable, /* optional */ keyfunc) {
  645. var m = MochiKit.Base;
  646. var self = MochiKit.Iter;
  647. if (arguments.length < 2) {
  648. keyfunc = m.operator.identity;
  649. }
  650. iterable = self.iter(iterable);
  651. var result = [];
  652. var first = true;
  653. var prev_key;
  654. var compare = m.compare;
  655. while (true) {
  656. try {
  657. var value = iterable.next();
  658. var key = keyfunc(value);
  659. } catch (e) {
  660. if (e == self.StopIteration) {
  661. break;
  662. }
  663. throw e;
  664. }
  665. if (first || compare(key, prev_key) !== 0) {
  666. var values = [];
  667. result.push([key, values]);
  668. }
  669. values.push(value);
  670. first = false;
  671. prev_key = key;
  672. }
  673. return result;
  674. },
  675. /** @id MochiKit.Iter.arrayLikeIter */
  676. arrayLikeIter: function (iterable) {
  677. var i = 0;
  678. return {
  679. repr: function () { return "arrayLikeIter(...)"; },
  680. toString: MochiKit.Base.forwardCall("repr"),
  681. next: function () {
  682. if (i >= iterable.length) {
  683. throw MochiKit.Iter.StopIteration;
  684. }
  685. return iterable[i++];
  686. }
  687. };
  688. },
  689. /** @id MochiKit.Iter.hasIterateNext */
  690. hasIterateNext: function (iterable) {
  691. return (iterable && typeof(iterable.iterateNext) == "function");
  692. },
  693. /** @id MochiKit.Iter.iterateNextIter */
  694. iterateNextIter: function (iterable) {
  695. return {
  696. repr: function () { return "iterateNextIter(...)"; },
  697. toString: MochiKit.Base.forwardCall("repr"),
  698. next: function () {
  699. var rval = iterable.iterateNext();
  700. if (rval === null || rval === undefined) {
  701. throw MochiKit.Iter.StopIteration;
  702. }
  703. return rval;
  704. }
  705. };
  706. }
  707. });
  708. MochiKit.Iter.EXPORT_OK = [
  709. "iteratorRegistry",
  710. "arrayLikeIter",
  711. "hasIterateNext",
  712. "iterateNextIter",
  713. ];
  714. MochiKit.Iter.EXPORT = [
  715. "StopIteration",
  716. "registerIteratorFactory",
  717. "iter",
  718. "count",
  719. "cycle",
  720. "repeat",
  721. "next",
  722. "izip",
  723. "ifilter",
  724. "ifilterfalse",
  725. "islice",
  726. "imap",
  727. "applymap",
  728. "chain",
  729. "takewhile",
  730. "dropwhile",
  731. "tee",
  732. "list",
  733. "reduce",
  734. "range",
  735. "sum",
  736. "exhaust",
  737. "forEach",
  738. "every",
  739. "sorted",
  740. "reversed",
  741. "some",
  742. "iextend",
  743. "groupby",
  744. "groupby_as_array"
  745. ];
  746. MochiKit.Iter.__new__ = function () {
  747. var m = MochiKit.Base;
  748. // Re-use StopIteration if exists (e.g. SpiderMonkey)
  749. if (typeof(StopIteration) != "undefined") {
  750. this.StopIteration = StopIteration;
  751. } else {
  752. /** @id MochiKit.Iter.StopIteration */
  753. this.StopIteration = new m.NamedError("StopIteration");
  754. }
  755. this.iteratorRegistry = new m.AdapterRegistry();
  756. // Register the iterator factory for arrays
  757. this.registerIteratorFactory(
  758. "arrayLike",
  759. m.isArrayLike,
  760. this.arrayLikeIter
  761. );
  762. this.registerIteratorFactory(
  763. "iterateNext",
  764. this.hasIterateNext,
  765. this.iterateNextIter
  766. );
  767. this.EXPORT_TAGS = {
  768. ":common": this.EXPORT,
  769. ":all": m.concat(this.EXPORT, this.EXPORT_OK)
  770. };
  771. m.nameFunctions(this);
  772. };
  773. MochiKit.Iter.__new__();
  774. //
  775. // XXX: Internet Explorer blows
  776. //
  777. if (MochiKit.__export__) {
  778. reduce = MochiKit.Iter.reduce;
  779. }
  780. MochiKit.Base._exportSymbols(this, MochiKit.Iter);