Fix Result.map when Array contains zero elements (#4036, #4048).

This commit is contained in:
Richard Moore 2023-05-15 17:18:46 -04:00
parent 6db7458cf0
commit 2e5935b91c

@ -211,6 +211,23 @@ export class Result extends Array<any> {
return new Result(_guard, result, names);
}
/**
* @_ignore
*/
map<T extends any = any>(callback: (el: any, index: number, array: Result) => T, thisArg?: any): Array<T> {
const result: Array<T> = [ ];
for (let i = 0; i < this.length; i++) {
const item = this[i];
if (item instanceof Error) {
throwError(`index ${ i }`, item);
}
result.push(callback.call(thisArg, item, i, this));
}
return result;
}
/**
* Returns the value for %%name%%.