mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 14:20:12 +00:00
Merge pull request #24053 from devrelm/devrelm/remove-extra-groupBy-generic
[Ramda] - Remove generic from groupBy curried function
This commit is contained in:
4
types/ramda/index.d.ts
vendored
4
types/ramda/index.d.ts
vendored
@@ -16,7 +16,7 @@
|
||||
// Nikita Moshensky <https://github.com/moshensky>
|
||||
// Ethan Resnick <https://github.com/ethanresnick>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.4
|
||||
// TypeScript Version: 2.6
|
||||
|
||||
declare let R: R.Static;
|
||||
|
||||
@@ -679,7 +679,7 @@ declare namespace R {
|
||||
* on each element, and grouping the results according to values returned.
|
||||
*/
|
||||
groupBy<T>(fn: (a: T) => string, list: ReadonlyArray<T>): { [index: string]: T[] };
|
||||
groupBy<T>(fn: (a: T) => string): <T>(list: ReadonlyArray<T>) => { [index: string]: T[] };
|
||||
groupBy<T>(fn: (a: T) => string): (list: ReadonlyArray<T>) => { [index: string]: T[] };
|
||||
|
||||
/**
|
||||
* Takes a list and returns a list of lists where each sublist's elements are all "equal" according to the provided equality function
|
||||
|
||||
@@ -664,6 +664,36 @@ interface Obj {
|
||||
byGrade(students);
|
||||
};
|
||||
|
||||
() => {
|
||||
interface MyObject {
|
||||
id: string;
|
||||
quantity: number;
|
||||
}
|
||||
|
||||
const reduceWithCombinedQuantities = (items: MyObject[]) =>
|
||||
items.reduce<MyObject>(
|
||||
(acc, item) => ({...item, quantity: acc.quantity + item.quantity}),
|
||||
{id: '', quantity: 0},
|
||||
);
|
||||
|
||||
const combineMyObjects = R.pipe(
|
||||
R.groupBy<MyObject>(s => s.id),
|
||||
R.values,
|
||||
R.map(reduceWithCombinedQuantities),
|
||||
);
|
||||
|
||||
const combined = combineMyObjects([
|
||||
{id: 'foo', quantity: 4},
|
||||
{id: 'bar', quantity: 3},
|
||||
{id: 'foo', quantity: 2},
|
||||
]);
|
||||
|
||||
return {
|
||||
id: combined[0].id,
|
||||
quantity: combined[0].quantity
|
||||
};
|
||||
};
|
||||
|
||||
() => {
|
||||
R.groupWith(R.equals)([0, 1, 1, 2, 3, 5, 8, 13, 21]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user