areDeterminer()
areDeterminer()
areDeterminer()
The function returns the object of every()
, forEach()
and some()
methods to check given values
with the test implemented by the given checkFn
function.
const areDeterminer = <CommonPayload extends object>(
checkFn: Function,
...values: any[]
) => {
return {
every: <Payload extends CommonPayload>(
callback: ResultCallback<any, Payload> = resultCallback,
payload?: Payload
): boolean =>
callback(
values.every((value) => checkFn(value)),
values,
payload
),
forEach: <Payload extends CommonPayload>(
forEachCallback: ForEachCallback<any, Payload>,
payload?: Payload
) => {
isArray(values) &&
isFunction(forEachCallback) &&
values.forEach((value, index) =>
forEachCallback(checkFn(value), value, index, values, payload)
);
},
some: <Payload extends CommonPayload>(
callback: ResultCallback<any, Payload> = resultCallback,
payload?: Payload
): boolean =>
callback(
isArray(values) ? values.some((value) => checkFn(value)) : false,
values,
payload
),
};
};
Generic type variables
CommonPayload
extends
object
CommonPayload
extends
object
The CommonPayload
generic type variable constrained by the object
constrains the generic type variable Payload
of each returned method.
Parameters
checkFn: Function
checkFn: Function
Function to test given values
.
...values: any[]
...values: any[]
A rest parameter of any
type to check its elements against test given in the checkFn
function.
Returns
The return value is an object
of every()
, some()
and forEach()
as methods of checking supplied values
.
Last updated
Was this helpful?