predictype

predictype v0.8.1


predictype / predicates/sets / setMembership

Function: setMembership()

setMembership<T>(source, oper, target): boolean

Defined in: predicates/sets/setMembership.ts:24

Checks membership conditions for elements in a set using the specified operation.

Type Parameters

T

T

Parameters

source

Set<T>

The set to check.

oper

SetMembershipOper

The membership operation to perform (e.g. ‘contains’, ‘excludes’).

target

T

The value to check for membership.

Returns

boolean

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

Throws

If the operation is not recognized.

Example

const s = new Set([1, 2, 3]);

setMembership(s, 'contains', 2); // true
setMembership(s, 'excludes', 4); // true

Remarks

Supported Operators: