| export function flatMapWithArgs(list, callback, ...args) { |
| const result = []; |
| for (const item of list) { |
| const itemResults = callback(item, ...args); |
| for (const itemResult of itemResults) { |
| result.push(itemResult); |
| } |
| } |
| return result; |
| } |
| export function mapWithArgs(list, callback, ...args) { |
| const result = Array.from({ length: list.length }); |
| for (const [index, item] of list.entries()) { |
| const itemResults = callback(item, ...args); |
| result[index] = itemResults; |
| } |
| return result; |
| } |
| export function filterWithArgs(list, callback, ...args) { |
| const result = []; |
| for (const item of list) { |
| if (callback(item, ...args)) { |
| result.push(item); |
| } |
| } |
| return result; |
| } |
| export function reduceWithArgs(list, callback, initialValue, ...args) { |
| let accumulator = initialValue; |
| for (const item of list) { |
| accumulator = callback(accumulator, item, ...args); |
| } |
| return accumulator; |
| } |
| export function getLastOrThrow(list) { |
| const lastItem = list.at(-1); |
| if (lastItem === undefined) { |
| throw new Error('No item in list exists'); |
| } |
| return lastItem; |
| } |
| //# sourceMappingURL=list.js.map |