@monstermann/fn
Version:
A utility library for TypeScript.
31 lines (29 loc) • 895 B
TypeScript
import { OrElse } from "./internals/types.js";
//#region src/array/removeLastOrElse.d.ts
/**
* `removeLastOrElse(target, value, orElse)`
*
* Removes the last occurrence of `value` from `target` array. If the value is not found, calls the `orElse` function with the original array and returns its result.
*
* ```ts
* removeLastOrElse([1, 2, 3, 2], 2, () => []); // [1, 2, 3]
* removeLastOrElse([1, 2, 3], 4, (arr) => arr); // [1, 2, 3]
* ```
*
* ```ts
* pipe(
* [1, 2, 3, 2],
* removeLastOrElse(2, () => []),
* ); // [1, 2, 3]
* pipe(
* [1, 2, 3],
* removeLastOrElse(4, (arr) => arr),
* ); // [1, 2, 3]
* ```
*/
declare const removeLastOrElse: {
<T, U>(value: NoInfer<T>, orElse: OrElse<T, U>): (target: readonly T[]) => T[] | U;
<T, U>(target: readonly T[], value: NoInfer<T>, orElse: OrElse<T, U>): T[] | U;
};
//#endregion
export { removeLastOrElse };