Finds the first element in an input sync iterable that satisfies a given predicate function. Returns the found element or undefined if none is found.
A function that accepts an input sync iterable and returns the found element or undefined.
const input = [1, 2, 3, 4];const isEven = (x: number) => x % 2 === 0;const foundSyncElement = findSync<number>(isEven)(input);console.log(foundSyncElement); // Logs 2
Available as find when imported from peter-piper/sync.
find
peter-piper/sync
The type of elements in the input sync iterable.
A predicate function to test each element of the input sync iterable.
Generated using TypeDoc
Finds the first element in an input sync iterable that satisfies a given predicate function. Returns the found element or undefined if none is found.
Returns
A function that accepts an input sync iterable and returns the found element or undefined.
Example
Remarks
Available as
find
when imported frompeter-piper/sync
.