@monstermann/fn
Version:
A utility library for TypeScript.
26 lines (24 loc) • 751 B
TypeScript
import { ArrayPredicate } from "./internals/types.js";
//#region src/array/findRemoveOrThrow.d.ts
/**
* `findRemoveOrThrow(array, predicate)`
*
* Finds the first element in `array` that satisfies the provided `predicate` function and removes it, returning a new array without the removed element, or throws an error if no element is found.
*
* ```ts
* findRemoveOrThrow([1, 2, 3, 4], (x) => x > 2); // [1, 2, 4]
* ```
*
* ```ts
* pipe(
* [1, 2, 3, 4],
* findRemoveOrThrow((x) => x > 2),
* ); // [1, 2, 4]
* ```
*/
declare const findRemoveOrThrow: {
<T>(predicate: ArrayPredicate<T>): (target: readonly T[]) => T[];
<T>(target: readonly T[], predicate: ArrayPredicate<T>): T[];
};
//#endregion
export { findRemoveOrThrow };