From cf6a1f14c58718036e5982bd15a887ebb72cdf7c Mon Sep 17 00:00:00 2001 From: Dave Tapley Date: Thu, 23 Jan 2025 18:18:50 -0700 Subject: [PATCH] filter over Map For https://github.com/ramda/ramda/pull/3507 --- test/filter.test.ts | 5 +++++ types/filter.d.ts | 12 ++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/test/filter.test.ts b/test/filter.test.ts index b4c5279..776b941 100644 --- a/test/filter.test.ts +++ b/test/filter.test.ts @@ -90,3 +90,8 @@ expectType<(number | undefined)[]>(filter(x => x != null, [] as (number | undefi // filter(() => narrow, dist) // no need for type annotations when using full signature expectType>(filter(isNotNil, {} as Dict)); + + +// filter(() => narrow)(dist) +expectType>(filter(isNotNil, new Map())); +expectType>(filter(gt5, new Map())); diff --git a/types/filter.d.ts b/types/filter.d.ts index 8e47ed2..5ad1af9 100644 --- a/types/filter.d.ts +++ b/types/filter.d.ts @@ -10,10 +10,18 @@ export function filter( (list: readonly B[]): P[]; }; -// filter(() => boolean) +// filter(() => boolean)(list | dict) export function filter( pred: (value: T) => boolean, -):

>(collection: C) => C; +): { + (map: Map): Map; +

>(collection: C): C; +}; + +// filter(() => narrow, map) +export function filter(pred: (val: T) => val is P, map: Map): Map; +// filter(() => boolean, map) +export function filter(pred: (val: T) => boolean, map: Map): Map; // filter(() => narrow, list) - readonly T[] falls into Record for some reason, so list needs to come first export function filter(pred: (val: T) => val is P, list: readonly T[]): P[];