predictype

predictype v0.8.1


predictype / predicates/maps / mapSize

Function: mapSize()

mapSize<K, V>(source, oper, target): boolean

Defined in: predicates/maps/mapSize.ts:30

Checks the size of a Map using the specified operation.

Type Parameters

K

K

V

V

Parameters

source

Map<K, V>

The Map to check.

oper

MapSizeOper

The size operation to perform (e.g. ‘size_equals’, ‘size_greater_than’).

target

number

The size to compare against.

Returns

boolean

True if the size check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example

const m1 = new Map([[1, 'a'], [2, 'b']]);
const m2 = new Map([[1, 'a']]);
const size2 = 2;
const size0 = 0;

mapSize(m1, 'size_equals', size2); // true
mapSize(m2, 'size_greater_than', size0); // true

Remarks

Supported Operators: