UNPKG

@monstermann/fn

Version:

A utility library for TypeScript.

43 lines (41 loc) 1.36 kB
import { MapGuard, MapPredicate } from "./internals/types.js"; //#region src/map/filter.d.ts /** * `filter(map, predicate)` * * Filters `map` by keeping only the entries where `predicate` returns true for the value. * * ```ts * filter( * new Map([ * ["a", 1], * ["b", 2], * ["c", 3], * ]), * (value) => value > 1, * ); // Map(2) { "b" => 2, "c" => 3 } * ``` * * ```ts * pipe( * new Map([ * ["a", 1], * ["b", 2], * ["c", 3], * ]), * filter((value) => value > 1), * ); // Map(2) { "b" => 2, "c" => 3 } * ``` */ declare const filter: { <K, V, U extends V>(predicate: MapGuard<K, V, U>): (target: Map<K, V>) => Map<K, U>; <K, V, U extends V>(predicate: MapGuard<K, V, U>): (target: ReadonlyMap<K, V>) => ReadonlyMap<K, U>; <K, V>(predicate: MapPredicate<K, V>): (target: Map<K, V>) => Map<K, V>; <K, V>(predicate: MapPredicate<K, V>): (target: ReadonlyMap<K, V>) => ReadonlyMap<K, V>; <K, V, U extends V>(target: Map<K, V>, predicate: MapGuard<K, V, U>): Map<K, U>; <K, V, U extends V>(target: ReadonlyMap<K, V>, predicate: MapGuard<K, V, U>): ReadonlyMap<K, U>; <K, V>(target: Map<K, V>, predicate: MapPredicate<K, V>): Map<K, V>; <K, V>(target: ReadonlyMap<K, V>, predicate: MapPredicate<K, V>): ReadonlyMap<K, V>; }; //#endregion export { filter };