From 5484a491668df1313d84b1e02e0221c62a6bc43c Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Fri, 19 Jul 2024 18:08:07 +0800 Subject: [PATCH] functional: add undefined checker --- src/functional.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/functional.ts b/src/functional.ts index 05c4e57..46ca2d4 100644 --- a/src/functional.ts +++ b/src/functional.ts @@ -6,3 +6,11 @@ export const sequence = (fn: ($: T) => Promise) => async (L: T[]) => { export const parallel = (fn: ($: T) => Promise) => async (L: T[]) => { await Promise.all(L.map(fn)); }; + + +export const notUndefined: ($: T | undefined) => T = $ => { + if ($ === undefined) + throw Error('the value is undefined!'); + else + return $; +};