twenty / packages /twenty-shared /src /utils /array /findOrThrow.ts
Jules
Initial clean CRM deployment with prebuilt assets
d9494a5
Raw
History Blame Contribute Delete
295 Bytes
import { assertIsDefinedOrThrow } from '@/utils';
export const findOrThrow = <T>(
array: T[],
predicate: (value: T) => boolean,
error: Error = new Error('Element not found'),
): T => {
const result = array.find(predicate);
assertIsDefinedOrThrow(result, error);
return result;
};