File size: 295 Bytes
d9494a5
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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;
};