predictype

predictype v0.8.1


predictype / predicates/sets / setState

Function: setState()

setState<T>(source, oper): boolean

Defined in: predicates/sets/setState.ts:29

Checks the state of a set using the specified operation.

Type Parameters

T

T

Parameters

source

Set<T>

The set to check.

oper

SetStateOper

The state operation to perform (e.g. ‘is_empty’, ‘has_primitives’).

Returns

boolean

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

Throws

If the operation is not recognized.

Example

const a = new Set();
const b = new Set([1]);
const c = new Set([1, 'hello', { id: 1 }]);

setState(a, 'is_empty'); // true
setState(b, 'is_not_empty'); // true
setState(c, 'has_primitives'); // true
setState(c, 'has_objects'); // true

Remarks

Supported Operators: