Skip to content

Commit e675668

Browse files
committed
generics/boolean -- not and or
1 parent 8bb9170 commit e675668

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

TODO.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
[docs] 总结各种 monad 的用法
2+
13
# 4.4 Dependencies Improve Search
24

35
> https://github.com/cicada-lang/propagator/issues/4
46
7+
generics/boolean.test
8+
59
propagators/boolean -- inverter
610
propagators/boolean.test -- inverter
711

src/generics/boolean.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defineGeneric, defineHandler } from "../generic/index.js"
2+
import { isBoolean } from "../utils/isBoolean.js"
3+
4+
export const not = defineGeneric()
5+
defineHandler(not, [isBoolean], (x) => !x)
6+
7+
export const and = defineGeneric()
8+
defineHandler(and, [isBoolean, isBoolean], (x) => x && y)
9+
10+
export const or = defineGeneric()
11+
defineHandler(or, [isBoolean, isBoolean], (x, y) => x || y)

src/utils/isBoolean.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function isBoolean(x: any): x is boolean {
2+
return typeof x === "boolean"
3+
}

0 commit comments

Comments
 (0)