You can not select more than 25 topics
Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
- /*
- * @Author: 赵伟
- * @Date: 2024-10-12 14:27:29
- * @Description: 函数式编程
- */
-
- /**
- * 安全调用函数,如果参数是 `undefined` 或 `null`,直接返回 `undefined` 或 `null`,而不会导致异常
- *
- * @param fn - 要调用的函数
- * @returns 封装后的函数,该函数的参数如果是 `undefined` 或 `null`,结果直接返回 `undefined` 或 `null`,而不会导致异常
- */
- export function safeInvoke<T, M>(
- fn: (value: T) => M | undefined | null,
- ): (value: T | undefined | null) => M | undefined | null {
- return (arg: T | undefined | null) => {
- if (arg === undefined || arg === null) {
- return arg as undefined | null;
- }
- return fn(arg);
- };
- }
|