Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | 13x 13x 13x 13x 34x 39x 2x 26x 39x 99x 13x 13x 5x 13x 13x | import { purry } from './purry';
import { _reduceLazy, LazyResult } from './_reduceLazy';
import { _toLazyIndexed } from './_toLazyIndexed';
import { Pred, PredIndexedOptional, PredIndexed } from './_types';
/**
* Map each element of an array using a defined callback function.
* @param array The array to map.
* @param fn The function mapper.
* @returns The new mapped array.
* @signature
* R.map(array, fn)
* R.map.indexed(array, fn)
* @example
* R.map([1, 2, 3], x => x * 2) // => [2, 4, 6]
* R.map.indexed([0, 0, 0], (x, i) => i) // => [0, 1, 2]
* @data_first
* @indexed
* @pipeable
* @category Array
*/
export function map<T, K>(array: T[], fn: Pred<T, K>): K[];
/**
* Map each value of an object using a defined callback function.
* @param fn the function mapper
* @signature
* R.map(fn)(array)
* R.map.indexed(fn)(array)
* @example
* R.pipe([0, 1, 2], R.map(x => x * 2)) // => [2, 4, 6]
* R.pipe([0, 0, 0], R.map.indexed((x, i) => i)) // => [0, 1, 2]
* @data_last
* @indexed
* @pipeable
* @category Array
*/
export function map<T, K>(fn: Pred<T, K>): (array: T[]) => K[];
export function map() {
return purry(_map(false), arguments, map.lazy);
}
const _map = (indexed: boolean) => <T, K>(
array: T[],
fn: PredIndexedOptional<T, K>
) => {
return _reduceLazy(
array,
indexed ? map.lazyIndexed(fn) : map.lazy(fn),
indexed
);
};
const _lazy = (indexed: boolean) => <T, K>(fn: PredIndexedOptional<T, K>) => {
return (value: T, index?: number, array?: T[]): LazyResult<K> => {
return {
done: false,
hasNext: true,
next: indexed ? fn(value, index, array) : fn(value),
};
};
};
export namespace map {
export function indexed<T, K>(array: T[], fn: PredIndexed<T, K>): K[];
export function indexed<T, K>(fn: PredIndexed<T, K>): (array: T[]) => K[];
export function indexed() {
return purry(_map(true), arguments, map.lazyIndexed);
}
export const lazy = _lazy(false);
export const lazyIndexed = _toLazyIndexed(_lazy(true));
}
|