Skip to content

Commit 266a9b2

Browse files
committed
extract reason/
1 parent 15bc1d9 commit 266a9b2

File tree

5 files changed

+18
-15
lines changed

5 files changed

+18
-15
lines changed

TODO.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
> - https://github.com/cicada-lang/propagator/issues/3
44
5+
assertBeliefSystemReasons
56
barometer-belief-system.test.ts -- finishing
67
`beliefSystemQuery`
78

src/belief-system/beliefSystemMerge.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { Belief, isBelief, type Reasons } from "../belief/index.js"
1+
import { Belief, isBelief } from "../belief/index.js"
22
import { isNothing, nothing, type Nothing } from "../cell/index.js"
33
import { implies, merge, type MergeConflict } from "../merge/index.js"
4+
import type { Reasons } from "../reason/index.js"
45
import { setIsSubsetOf } from "../utils/Set.js"
56
import { BeliefSystem } from "./BeliefSystem.js"
67

src/belief/Belief.ts

+3-14
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
11
import assert from "node:assert"
2+
import { toReasons, type Reasons } from "../reason/index.js"
23
import { isNonNullObject } from "../utils/isNonNullObject.js"
34
import { log } from "../utils/log.js"
45

5-
export type Reason = string
6-
export type Reasons = Set<Reason>
7-
export type ReasonLike = Reasons | Array<Reason>
8-
9-
export function toReason(x: ReasonLike): Reasons {
10-
if (x instanceof Array) {
11-
return new Set(x)
12-
}
13-
14-
return x
15-
}
16-
176
export type Belief<T> = {
187
"@type": "Belief"
198
value: T
@@ -24,7 +13,7 @@ export function Belief<T>(
2413
value: T,
2514
reasons: Reasons | Array<string>,
2615
): Belief<T> {
27-
reasons = toReason(reasons)
16+
reasons = toReasons(reasons)
2817

2918
return {
3019
"@type": "Belief",
@@ -60,7 +49,7 @@ export function assertBeliefReasons(
6049
}
6150

6251
if (reasons !== undefined) {
63-
reasons = toReason(reasons)
52+
reasons = toReasons(reasons)
6453

6554
assert.deepStrictEqual(target.reasons, reasons)
6655
}

src/reason/Reason.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export type Reason = string
2+
export type Reasons = Set<Reason>
3+
export type ReasonLike = Reasons | Array<Reason>
4+
5+
export function toReasons(x: ReasonLike): Reasons {
6+
if (x instanceof Array) {
7+
return new Set(x)
8+
}
9+
10+
return x
11+
}

src/reason/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./Reason.js"

0 commit comments

Comments
 (0)