array-fp-utils
Advanced tools
Comparing version 0.4.0 to 0.5.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.uniqueBy = void 0; | ||
const uniqueBy = (getUniqueKey, reduceValue = (prevValue) => prevValue) => (arr) => { | ||
const map = arr.reduce((acc, value) => { | ||
exports.uniqueBy = exports._uniqueBy = void 0; | ||
function _uniqueBy(arr, getUniqueKey, reduceValue = (prevValue) => prevValue) { | ||
const map = new Map(); | ||
for (const value of arr) { | ||
const key = getUniqueKey(value); | ||
const existingValue = acc.get(key); | ||
const existingValue = map.get(key); | ||
if (!existingValue) { | ||
acc.set(key, value); | ||
map.set(key, value); | ||
} | ||
else { | ||
acc.set(key, reduceValue(existingValue, value)); | ||
map.set(key, reduceValue(existingValue, value)); | ||
} | ||
return acc; | ||
}, new Map()); | ||
} | ||
return Array.from(map.values()); | ||
}; | ||
} | ||
exports._uniqueBy = _uniqueBy; | ||
const uniqueBy = (getUniqueKey, reduceValue = (prevValue) => prevValue) => (arr) => _uniqueBy(arr, getUniqueKey, reduceValue); | ||
exports.uniqueBy = uniqueBy; |
@@ -1,14 +0,15 @@ | ||
export const uniqueBy = (getUniqueKey, reduceValue = (prevValue) => prevValue) => (arr) => { | ||
const map = arr.reduce((acc, value) => { | ||
export function _uniqueBy(arr, getUniqueKey, reduceValue = (prevValue) => prevValue) { | ||
const map = new Map(); | ||
for (const value of arr) { | ||
const key = getUniqueKey(value); | ||
const existingValue = acc.get(key); | ||
const existingValue = map.get(key); | ||
if (!existingValue) { | ||
acc.set(key, value); | ||
map.set(key, value); | ||
} | ||
else { | ||
acc.set(key, reduceValue(existingValue, value)); | ||
map.set(key, reduceValue(existingValue, value)); | ||
} | ||
return acc; | ||
}, new Map()); | ||
} | ||
return Array.from(map.values()); | ||
}; | ||
} | ||
export const uniqueBy = (getUniqueKey, reduceValue = (prevValue) => prevValue) => (arr) => _uniqueBy(arr, getUniqueKey, reduceValue); |
import { Primitive } from '../types'; | ||
export declare function isDistinctArray(arr: Readonly<Array<Primitive>>): boolean; | ||
export declare function isDistinctArray(arr: ReadonlyArray<Primitive>): boolean; | ||
//# sourceMappingURL=isDistinctArray.d.ts.map |
export type NonEmptyArray<T> = [T, ...T[]]; | ||
export type NonEmptyArrayAlt<A> = Array<A> & { | ||
0: A; | ||
export type NonEmptyArrayAlt<T> = Array<T> & { | ||
0: T; | ||
}; | ||
export type Primitive = string | number | boolean | bigint | symbol | null | undefined; | ||
//# sourceMappingURL=types.d.ts.map |
@@ -1,2 +0,4 @@ | ||
export declare const uniqueBy: <ValueType, KeyType_1>(getUniqueKey: (value: ValueType) => KeyType_1, reduceValue?: (prevValue: ValueType, nextValue: ValueType) => ValueType) => (arr: readonly ValueType[]) => ValueType[]; | ||
import { NonEmptyArray, NonEmptyArrayAlt } from '../types'; | ||
export declare function _uniqueBy<T extends ReadonlyArray<unknown> | Readonly<NonEmptyArray<unknown>> | Readonly<NonEmptyArrayAlt<unknown>>, K>(arr: T, getUniqueKey: (value: T[number]) => K, reduceValue?: (prevValue: T[number], nextValue: T[number]) => T[number]): T; | ||
export declare const uniqueBy: <T extends readonly unknown[] | readonly [unknown, ...unknown[]] | Readonly<NonEmptyArrayAlt<unknown>>, K>(getUniqueKey: (value: T[number]) => K, reduceValue?: (prevValue: T[number], nextValue: T[number]) => T[number]) => (arr: T) => T; | ||
//# sourceMappingURL=uniqueBy.d.ts.map |
{ | ||
"name": "array-fp-utils", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "Array utilities for functional programming in TypeScript.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31660
334