@salesforce/source-deploy-retrieve
Version:
JavaScript library to run Salesforce metadata deploys and retrieves
87 lines • 2.86 kB
JavaScript
/*
* Copyright 2025, Salesforce, Inc.
*
* 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.LazyCollection = void 0;
class LazyCollection {
iterable;
constructor(iterable) {
this.iterable = iterable;
}
first() {
return this.getIterator().next().value;
}
find(predicate) {
const iter = this.getIterator();
let next = iter.next();
while (!next.done) {
if (predicate(next.value)) {
return next.value;
}
next = iter.next();
}
}
filter(predicate) {
const iter = this.getIterator();
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: valid syntax - invokes the constructor of the instance's type
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return new this.constructor((function* () {
let next = iter.next();
while (!next.done) {
if (predicate(next.value)) {
yield next.value;
}
next = iter.next();
}
})());
}
map(mapper) {
const iter = this.getIterator();
return new LazyCollection((function* () {
let next = iter.next();
while (!next.done) {
yield mapper(next.value);
next = iter.next();
}
})());
}
toArray() {
const result = [];
const iter = this.getIterator();
let next = iter.next();
while (!next.done) {
result.push(next.value);
next = iter.next();
}
return result;
}
/**
* USE getIterator() IN METHOD IMPLEMENTATIONS
*
* This is to support for..of syntax on non-subclass instances of
* LazyCollection. getIterator() ensures we use [Symbol.iterator] of the
* subclass if `iterable` is not set.
*/
[Symbol.iterator]() {
return this.iterable ? this.iterable[Symbol.iterator]() : [][Symbol.iterator]();
}
getIterator() {
return this.iterable ? this.iterable[Symbol.iterator]() : this[Symbol.iterator]();
}
}
exports.LazyCollection = LazyCollection;
//# sourceMappingURL=lazyCollection.js.map
;