@augment-vir/common
Version:
A collection of augments, helpers types, functions, and classes for any JavaScript environment.
33 lines (32 loc) • 757 B
JavaScript
/**
* Performs
* [`[].map()`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/map)
* on an array but transfers the input tuple's size to the output type.
*
* @category Array
* @category Package : @augment-vir/common
* @example
*
* ```ts
* import {typedMap} from '@augment-vir/common';
*
* const result = await typedMap(
* [
* 1,
* 2,
* 3,
* 4,
* 5,
* ],
* (value) => {
* return value + 1;
* },
* );
* ```
*
* @returns A new array (does not mutate).
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
*/
export function typedMap(arrayToMap, mapCallback) {
return arrayToMap.map(mapCallback);
}