1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 384× 1× 1× 1× 90× 1× 89× 56× 33× 28× 28× 5× 4× 2× 2× 1× 1× 2× 1× 1× 55× 1× 1× 6× 1× 1× 94× 1× 1× 3× 1× 1× 145× 145× 145× 144× 50× 50× 50× 222× 22× 50× 94× 46× 46× 46× 289× 3× 46× 48× 46× 46× 2× 3× 1× 1× 2× 2× 2× 2× 1× 1× 1× | /*! * @author electricessence / https://github.com/electricessence/ * Licensing: MIT https://github.com/electricessence/TypeScript.NET/blob/master/LICENSE.md */ (function (factory) { Eif (typeof module === 'object' && typeof module.exports === 'object') { var v = factory(require, exports); Iif (v !== undefined) module.exports = v; } else if (typeof define === 'function' && define.amd) { define(["require", "exports", "../../Disposable/dispose", "../../Types", "./ArrayEnumerator", "./IndexEnumerator", "./UnsupportedEnumerableException", "./InfiniteEnumerator", "./EmptyEnumerator", "./IteratorEnumerator"], factory); } })(function (require, exports) { "use strict"; var dispose_1 = require("../../Disposable/dispose"); var Types_1 = require("../../Types"); var ArrayEnumerator_1 = require("./ArrayEnumerator"); var IndexEnumerator_1 = require("./IndexEnumerator"); var UnsupportedEnumerableException_1 = require("./UnsupportedEnumerableException"); var InfiniteEnumerator_1 = require("./InfiniteEnumerator"); var EmptyEnumerator_1 = require("./EmptyEnumerator"); var IteratorEnumerator_1 = require("./IteratorEnumerator"); var VOID0 = void (0), STRING_EMPTY = "", ENDLESS_EXCEPTION_MESSAGE = 'Cannot call forEach on an endless enumerable. ' + 'Would result in an infinite loop that could hang the current process.'; function throwIfEndless(isEndless) { Iif (isEndless) throw new UnsupportedEnumerableException_1.UnsupportedEnumerableException(ENDLESS_EXCEPTION_MESSAGE); } exports.throwIfEndless = throwIfEndless; function initArrayFrom(source, max) { if (max === void 0) { max = Infinity; } if (Array.isArray(source) || Types_1.Type.isString(source)) { var len = Math.min(source.length, max); if (isFinite(len)) { if (len > 65535) return new Array(len); var result = []; result.length = len; return result; } } return []; } function from(source) { if (!source) return EmptyEnumerator_1.EmptyEnumerator; if (Array.isArray(source)) return new ArrayEnumerator_1.ArrayEnumerator(source); if (Types_1.Type.isArrayLike(source)) { return new IndexEnumerator_1.IndexEnumerator(function () { return { source: source, length: source.length, pointer: 0, step: 1 }; }); } if (!Types_1.Type.isPrimitive(source)) { if (isEnumerable(source)) return source.getEnumerator(); if (Types_1.Type.isFunction(source)) return new InfiniteEnumerator_1.InfiniteEnumerator(source); Iif (isIterator(source)) return new IteratorEnumerator_1.IteratorEnumerator(source); } throw new UnsupportedEnumerableException_1.UnsupportedEnumerableException(); } exports.from = from; function isEnumerable(instance) { return Types_1.Type.hasMemberOfType(instance, "getEnumerator", Types_1.Type.FUNCTION); } exports.isEnumerable = isEnumerable; function isEnumerableOrArrayLike(instance) { return Types_1.Type.isArrayLike(instance) || isEnumerable(instance); } exports.isEnumerableOrArrayLike = isEnumerableOrArrayLike; function isEnumerator(instance) { return Types_1.Type.hasMemberOfType(instance, "moveNext", Types_1.Type.FUNCTION); } exports.isEnumerator = isEnumerator; function isIterator(instance) { return Types_1.Type.hasMemberOfType(instance, "next", Types_1.Type.FUNCTION); } exports.isIterator = isIterator; function forEach(e, action, max) { if (max === void 0) { max = Infinity; } Iif (e === STRING_EMPTY) return 0; if (e && max > 0) { if (Types_1.Type.isArrayLike(e)) { throwIfEndless(!isFinite(max) && !isFinite(e.length)); var i = 0; for (; i < Math.min(e.length, max); i++) { if (action(e[i], i) === false) break; } return i; } if (isEnumerator(e)) { throwIfEndless(!isFinite(max) && e.isEndless); var i = 0; while (max > i && e.moveNext()) { if (action(e.current, i++) === false) break; } return i; } if (isEnumerable(e)) { throwIfEndless(!isFinite(max) && e.isEndless); return dispose_1.using(e.getEnumerator(), function (f) { return forEach(f, action, max); }); } Iif (isIterator(e)) { throwIfEndless(!isFinite(max)); var i = 0, r = void 0; while (max > i && !(r = e.next()).done) { if (action(r.value, i++) === false) break; } return i; } } return -1; } exports.forEach = forEach; function toArray(source, max) { Eif (max === void 0) { max = Infinity; } Iif (source === STRING_EMPTY) return []; Eif (!isFinite(max) && Array.isArray(source)) return source.slice(); var result = initArrayFrom(source, max); if (-1 === forEach(source, function (e, i) { result[i] = e; }, max)) throw new UnsupportedEnumerableException_1.UnsupportedEnumerableException(); return result; } exports.toArray = toArray; function map(source, selector, max) { if (max === void 0) { max = Infinity; } if (source === STRING_EMPTY) return []; if (!isFinite(max) && Array.isArray(source)) return source.map(selector); var result = initArrayFrom(source, max); if (-1 === forEach(source, function (e, i) { result[i] = selector(e); }, max)) throw new UnsupportedEnumerableException_1.UnsupportedEnumerableException(); return result; } exports.map = map; }); //# sourceMappingURL=Enumerator.js.map |