# all files / TypeScript.NET/dist/commonjs/System/Collections/Enumeration/ Enumerator.js

53.52% Statements 38/71
20.59% Branches 7/34
33.33% Functions 6/18
48% Lines 24/50

    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

    6×

    1×

    1×
    1×
    1×
    1×

    1×
    1×
    1×

    1×

    1×

    1×
    1×
    1×
    1×

    1×
    1×

    1×
    1×

    1×
    1×

    1×
    1×

    1×

     /*!
     * @author electricessence / https://github.com/electricessence/
     * Licensing: MIT https://github.com/electricessence/TypeScript.NET/blob/master/LICENSE.md
     */
    'use strict';

    var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { Eif (protoProps) defineProperties(Constructor.prototype, protoProps); Iif (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

    function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

    var Types_1 = require("../../Types");
    var ArrayEnumerator_1 = require("./ArrayEnumerator");
    var IndexEnumerator_1 = require("./IndexEnumerator");
    var VOID0 = void 0;

    var EmptyEnumerator = function () {
        function EmptyEnumerator() {
            _classCallCheck(this, EmptyEnumerator);
        }

        _createClass(EmptyEnumerator, [{
            key: "moveNext",
            value: function moveNext() {
                return false;
            }
        }, {
            key: "nextValue",
            value: function nextValue() {
                return VOID0;
            }
        }, {
            key: "next",
            value: function next() {
                return {
                    value: VOID0,
                    done: true
                };
            }
        }, {
            key: "reset",
            value: function reset() {}
        }, {
            key: "dispose",
            value: function dispose() {}
        }, {
            key: "current",
            get: function get() {
                return VOID0;
            }
        }]);

        return EmptyEnumerator;
    }();

    var Empty = new EmptyEnumerator();
    Object.freeze(Empty);
    exports.empty = Empty;
    function from(source) {
        if (!source) return Empty;
        if (Array.isArray(source)) return new ArrayEnumerator_1.default(source);
        if (Types_1.default.isArrayLike(source)) {
            return new IndexEnumerator_1.default(function () {
                return {
                    source: source,
                    length: source.length,
                    pointer: 0,
                    step: 1
                };
            });
        }
        if (!Types_1.default.isPrimitive(source)) {
            if (isEnumerable(source)) return source.getEnumerator();
        }
        throw new Error("Unknown enumerable.");
    }
    exports.from = from;
    function isEnumerable(instance) {
        return Types_1.default.hasMemberOfType(instance, "getEnumerator", Types_1.default.FUNCTION);
    }
    exports.isEnumerable = isEnumerable;
    function isEnumerableOrArrayLike(instance) {
        return Types_1.default.isArrayLike(instance) || isEnumerable(instance);
    }
    exports.isEnumerableOrArrayLike = isEnumerableOrArrayLike;
    function isEnumerator(instance) {
        return Types_1.default.hasMemberOfType(instance, "moveNext", Types_1.default.FUNCTION);
    }
    exports.isEnumerator = isEnumerator;
    function forEach(e, action) {
        if (e) {
            if (Types_1.default.isArrayLike(e)) {
                for (var i = 0; i < e.length; i++) {
                    if (action(e[i], i) === false) break;
                }return;
            }
            if (isEnumerable(e)) {
                e = e.getEnumerator();
            }
            if (isEnumerator(e)) {
                var index = 0;
                while (e.moveNext()) {
                    if (action(e.current, index++) === false) break;
                }
            }
        }
    }
    exports.forEach = forEach;
    //# sourceMappingURL=Enumerator.js.map