UNPKG

tamda

Version:

Practical functional programming library for TypeScript

17 lines 680 B
import { identity } from '../function/identity'; import { infer } from '../function/infer'; export function partition() { return inferred.apply(undefined, arguments); } const inferred = infer((array, keyFn = identity) => Array.from(array.reduce((map, item, index) => { const key = keyFn(item, index, array); // Initializes the array if undefined for the key. if (!map.get(key)) { map.set(key, []); } // Faster than spreading the array,safe here. // i.e. map.set(key, [ ...map.get(key), item ]), map.get(key).push(item); return map; }, new Map())), args => args[0] instanceof Array); //# sourceMappingURL=partition.js.map