"use strict";
/*!
  Copyright 2018 Ron Buckton (rbuckton@chronicles.org)

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
 */
/** @module "iterable-query/fn" */
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var internal_1 = require("../internal");
function scan(source, accumulator, seed) {
    internal_1.assert.mustBeQueryable(source, "source");
    internal_1.assert.mustBeFunction(accumulator, "accumulator");
    return new ScanIterable(internal_1.ToIterable(source), accumulator, arguments.length > 2, seed);
}
exports.scan = scan;
var ScanIterable = /** @class */ (function () {
    function ScanIterable(source, accumulator, isSeeded, seed) {
        this._source = source;
        this._accumulator = accumulator;
        this._isSeeded = isSeeded;
        this._seed = seed;
    }
    ScanIterable.prototype[Symbol.iterator] = function () {
        var e_1, _a, accumulator, hasCurrent, current, offset, _b, _c, value, e_1_1;
        return tslib_1.__generator(this, function (_d) {
            switch (_d.label) {
                case 0:
                    accumulator = this._accumulator;
                    hasCurrent = this._isSeeded;
                    current = this._seed;
                    offset = 0;
                    _d.label = 1;
                case 1:
                    _d.trys.push([1, 8, 9, 10]);
                    _b = tslib_1.__values(this._source), _c = _b.next();
                    _d.label = 2;
                case 2:
                    if (!!_c.done) return [3 /*break*/, 7];
                    value = _c.value;
                    if (!!hasCurrent) return [3 /*break*/, 3];
                    current = value;
                    hasCurrent = true;
                    return [3 /*break*/, 5];
                case 3:
                    current = accumulator(current, value, offset);
                    return [4 /*yield*/, current];
                case 4:
                    _d.sent();
                    _d.label = 5;
                case 5:
                    offset++;
                    _d.label = 6;
                case 6:
                    _c = _b.next();
                    return [3 /*break*/, 2];
                case 7: return [3 /*break*/, 10];
                case 8:
                    e_1_1 = _d.sent();
                    e_1 = { error: e_1_1 };
                    return [3 /*break*/, 10];
                case 9:
                    try {
                        if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
                    }
                    finally { if (e_1) throw e_1.error; }
                    return [7 /*endfinally*/];
                case 10: return [2 /*return*/];
            }
        });
    };
    ScanIterable = tslib_1.__decorate([
        internal_1.ToStringTag("ScanIterable")
    ], ScanIterable);
    return ScanIterable;
}());
//# sourceMappingURL=scan.js.map