removeOrElse
ts
function Array.removeOrElse<T, U>(
target: readonly T[],
value: NoInfer<T>,
orElse: (target: readonly NoInfer<T>[]) => U,
): T[] | URemoves the first occurrence of value from target array. If the value is not found, calls the orElse function with the original array and returns its result.
Example
ts
import { Array } from "@monstermann/array";
Array.removeOrElse([1, 2, 3, 2], 2, () => []); // [1, 3, 2]
Array.removeOrElse([1, 2, 3], 4, (arr) => arr); // [1, 2, 3]ts
import { Array } from "@monstermann/array";
pipe(
[1, 2, 3, 2],
Array.removeOrElse(2, () => []),
); // [1, 3, 2]
pipe(
[1, 2, 3],
Array.removeOrElse(4, (arr) => arr),
); // [1, 2, 3]