"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.switchScan = void 0;
const switchMap_js_1 = require("./switchMap.js");
const Observable_js_1 = require("../Observable.js");
function switchScan(accumulator, seed) {
    return (source) => new Observable_js_1.Observable((destination) => {
        let state = seed;
        (0, switchMap_js_1.switchMap)((value, index) => accumulator(state, value, index))(source).subscribe((0, Observable_js_1.operate)({
            destination,
            next: (innerValue) => {
                state = innerValue;
                destination.next(innerValue);
            },
        }));
        return () => {
            state = null;
        };
    });
}
exports.switchScan = switchScan;