From a4c14c4ecab97442b936e502623ab5190617d9a6 Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Sun, 1 Sep 2024 22:15:11 +0800 Subject: [PATCH] Use monads pkg --- commitlint/tests/integration.test.ts | 26 ++++++++------------------ package.json | 1 + 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/commitlint/tests/integration.test.ts b/commitlint/tests/integration.test.ts index 4ec99d76..4268dbf1 100644 --- a/commitlint/tests/integration.test.ts +++ b/commitlint/tests/integration.test.ts @@ -1,5 +1,6 @@ import { runCommitLintOnMsg } from "./testHelpers.js"; import { test, expect } from "vitest"; +import { Option, Some, None } from "@thames/monads"; class A { x: string; @@ -50,16 +51,6 @@ function fn(p: C) { } } -class None {} -class Value { - value: T; - - constructor(val: T) { - this.value = val; - } -} -type Option = None | Value; - test("testing DUs", () => { let foo = new A(); expect(foo.x).toBe("hello"); @@ -75,17 +66,16 @@ test("testing DUs", () => { }); function fnO(option: Option) { - if (option instanceof None) { - return "NAH"; - } else { - let val = option.value; - return (val * val).toString(); - } + const message = option.match({ + some: (res) => (res * res).toString(), + none: "NAH", + }); + return message; } test("testing Options", () => { - let foo: Option = new None(); - let bar: Option = new Value(2); + let foo: Option = None; + let bar: Option = Some(2); expect(fnO(foo)).toBe("NAH"); expect(fnO(bar)).toBe("4"); }); diff --git a/package.json b/package.json index baaba992..491f59ac 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "type": "module", "dependencies": { + "@thames/monads": "^0.7.0", "cosmiconfig": "9.0.0" }, "devDependencies": {