@altostra/core
Version:
Core library for shared types and logic
27 lines (26 loc) • 931 B
TypeScript
/**
* Projects all item from a source `Iterable` without throwing, and returns the results
* alongside the errors.
* @param source The iterable to get items from
* @param projection A function to transform each item in source
* @returns A pair where the first item is an array of all the transformed results
* and the second item is an array of errors occurred in the process
*/
export declare function safeMap<In, Out>(source: Iterable<In>, projection: (item: In, index: number) => Out): [results: Out[], errors: ProjectionError<In>[]];
/**
* An error that was thrown while transforming an item from a source iterable
*/
export interface ProjectionError<T> {
/**
* The error that was thrown
*/
error: unknown;
/**
* The index of the item that was transformed when the error was thrown
*/
index: number;
/**
* The item that was transformed when the error was thrown
*/
item: T;
}