86 lines
2.4 KiB
JavaScript
86 lines
2.4 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.IterableAccess = exports.MapAccess = void 0;
|
|
exports.isVisitor = isVisitor;
|
|
const utils_1 = require("../utils");
|
|
const generic_1 = require("./generic");
|
|
class MapAccess {
|
|
orDefaultSeed(seed) {
|
|
return seed || generic_1.GenericSeed.deserialize;
|
|
}
|
|
nextEntrySeed(kseed, vseed) {
|
|
const key = this.nextKeySeed(kseed);
|
|
if (!key.done) {
|
|
const value = this.nextValueSeed(vseed);
|
|
if (!value.done) {
|
|
return utils_1.IterResult.Next([key.value, value.value]);
|
|
}
|
|
}
|
|
return utils_1.IterResult.Done();
|
|
}
|
|
nextKey() {
|
|
return this.nextKeySeed(generic_1.GenericSeed.deserialize);
|
|
}
|
|
nextValue() {
|
|
return this.nextValueSeed(generic_1.GenericSeed.deserialize);
|
|
}
|
|
nextEntry() {
|
|
const key = this.nextKey();
|
|
if (!key.done) {
|
|
const value = this.nextValue();
|
|
if (!value.done) {
|
|
return utils_1.IterResult.Next([key.value, value.value]);
|
|
}
|
|
}
|
|
return utils_1.IterResult.Done();
|
|
}
|
|
*generate(next) {
|
|
let item;
|
|
while ((item = next()) && !item.done) {
|
|
yield item.value;
|
|
}
|
|
}
|
|
keys(seed) {
|
|
return this.generate(seed == null ?
|
|
this.nextKey.bind(this) :
|
|
this.nextKeySeed.bind(this, seed));
|
|
}
|
|
values(seed) {
|
|
return this.generate(seed == null ?
|
|
this.nextValue.bind(this) :
|
|
this.nextValueSeed.bind(this, seed));
|
|
}
|
|
entries(kseed, vseed) {
|
|
return this.generate(kseed == null && vseed == null ?
|
|
this.nextEntry.bind(this) :
|
|
this.nextEntrySeed.bind(this, this.orDefaultSeed(kseed), this.orDefaultSeed(vseed)));
|
|
}
|
|
[Symbol.iterator]() {
|
|
return this.entries();
|
|
}
|
|
}
|
|
exports.MapAccess = MapAccess;
|
|
class IterableAccess {
|
|
nextElement() {
|
|
return this.nextElementSeed(generic_1.GenericSeed.deserialize);
|
|
}
|
|
[Symbol.iterator]() {
|
|
return {
|
|
next: this.nextElement.bind(this)
|
|
};
|
|
}
|
|
}
|
|
exports.IterableAccess = IterableAccess;
|
|
const VisitorMethods = Object.freeze([
|
|
'visitBoolean',
|
|
'visitNumber',
|
|
'visitBigInt',
|
|
'visitString',
|
|
'visitSymbol',
|
|
'visitNull',
|
|
'visitObject',
|
|
'visitIterable'
|
|
]);
|
|
function isVisitor(visitor) {
|
|
return VisitorMethods.every(method => method in visitor);
|
|
}
|