🌳
pt0/sharedF/moDashF/findOnlyF.mts
4const findOnly = <T,>(arr: T[], predicate: (item: T) => boolean): T | undefined => {
5 const matches = arr.filter(predicate)
6 throwIf(() => matches.length > 1, {matchCount: matches.length, matches})
7 return matches[0]
8}
10export const findOnlyReq = <T,>(arr: T[], predicate: (item: T) => boolean): T => {
11 const result = findOnly(arr, predicate)
12 assertDefined(result, {arr})
13 return result