collectype / factory/maps/mapValue / mapValueFactory
mapValueFactory<
T,C>(ctx,oper): <K>(field,target) =>C
Defined in: factory/maps/mapValue.ts:40
Creates a predicate filter for map value using PredicType.map.value.
T
The item type in the collection.
C extends Wherable<T, C>
The Wherable context type (must extend Wherable<T, C>).
C
The context (usually a collection) supporting the where method.
MapValueOper
The map value operation (e.g., ‘containsValue’, ‘lacksValue’, etc.).
Returns a function that takes a field (of type Map on T) and a target value, and applies the map value predicate to filter the context.
<
K>(field,target):C
K extends string | number | symbol
K
unknown
C
// Example: Composing a map value filter as a property, homogeneous model
import { BaseFunctions } from 'collectype';
import { mapValueFactory } from 'collectype';
type Person = { name: string; scores: Map<string, number> };
class PersonFunctions extends BaseFunctions<Person> {
mapContainsValue = mapValueFactory<Person, this>(this, 'containsValue');
}
// Usage:
const people: Person[] = [
{ name: 'Alice', scores: new Map([['math', 18], ['english', 15]]) },
{ name: 'Bob', scores: new Map([['math', 10]]) }
];
const fn = new PersonFunctions(people);
const filtered = fn.mapContainsValue('scores', 15);
// filtered contains the items where 'scores' contains the value 15