Skip to content

Commit

Permalink
Use monads pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
knocte committed Sep 1, 2024
1 parent 6e8bbab commit e19be4f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
25 changes: 8 additions & 17 deletions commitlint/tests/integration.test.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -50,15 +51,6 @@ function fn(p: C) {
}
}

class None {}
class Value<T> {
value: T;

constructor(val: T) {
this.value = val;
}
}
type Option<T> = None | Value<T>;

test("testing DUs", () => {
let foo = new A();
Expand All @@ -75,17 +67,16 @@ test("testing DUs", () => {
});

function fnO(option: Option<number>) {
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<number> = new None();
let bar: Option<number> = new Value(2);
let foo: Option<number> = None;
let bar: Option<number> = Some(2);
expect(fnO(foo)).toBe("NAH");
expect(fnO(bar)).toBe("4");
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"type": "module",
"dependencies": {
"@thames/monads": "^0.7.0",
"cosmiconfig": "9.0.0"
},
"devDependencies": {
Expand Down

0 comments on commit e19be4f

Please sign in to comment.