functional: add undefined checker

This commit is contained in:
2024-07-19 18:08:07 +08:00
parent 78f4885647
commit 5484a49166

View File

@@ -6,3 +6,11 @@ export const sequence = <T, U>(fn: ($: T) => Promise<U>) => async (L: T[]) => {
export const parallel = <T, U>(fn: ($: T) => Promise<U>) => async (L: T[]) => {
await Promise.all(L.map(fn));
};
export const notUndefined: <T>($: T | undefined) => T = $ => {
if ($ === undefined)
throw Error('the value is undefined!');
else
return $;
};