From 4895420ff3300c84f5fe3ec3b97aab7a64710092 Mon Sep 17 00:00:00 2001 From: Xie Yuheng Date: Mon, 24 Jun 2024 06:33:06 +0800 Subject: [PATCH] monads/nothing-monad --- TODO.md | 1 - src/monads/nothing-monad.ts | 7 +++++++ src/utils/isFunction.ts | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/monads/nothing-monad.ts create mode 100644 src/utils/isFunction.ts diff --git a/TODO.md b/TODO.md index 6a93fd5..dc51c32 100644 --- a/TODO.md +++ b/TODO.md @@ -1,4 +1,3 @@ -monads/nothing-monad 用 generic 函数定义 lift -- 删除 `skipIncompleteInputs` monads/supported-monad -- 删除 `maybeUnwrapSupported` diff --git a/src/monads/nothing-monad.ts b/src/monads/nothing-monad.ts new file mode 100644 index 0000000..42415fd --- /dev/null +++ b/src/monads/nothing-monad.ts @@ -0,0 +1,7 @@ +import { isNothing, nothing } from "../cell/Nothing.js" +import { defineHandler } from "../generic/index.js" +import { fmap, join } from "../monad/index.js" +import { isFunction } from "../utils/isFunction.js" + +defineHandler(fmap, [isFunction, isNothing], (f, mx) => nothing) +defineHandler(join, [isNothing], (mmx) => nothing) diff --git a/src/utils/isFunction.ts b/src/utils/isFunction.ts new file mode 100644 index 0000000..c9fcf05 --- /dev/null +++ b/src/utils/isFunction.ts @@ -0,0 +1,3 @@ +export function isFunction(x: any): x is Function { + return typeof x === "function" +}