Skip to content

Commit

Permalink
beliefEqual & beliefSystemEqual take optional valueEqual
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Sep 6, 2024
1 parent 3e9e572 commit 6824936
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 17 deletions.
2 changes: 0 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
`beliefEqual` take optional `valueEqual`

# 4.4 Dependencies Improve Search

> https://github.com/cicada-lang/propagator/issues/4
Expand Down
6 changes: 3 additions & 3 deletions src/belief-system/beliefSystemEqual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import type { BeliefSystem } from "./BeliefSystem.js"
export function beliefSystemEqual<A>(
x: BeliefSystem<A>,
y: BeliefSystem<A>,
options: {
valueEqual: (x: A, y: A) => boolean
options?: {
valueEqual?: (x: A, y: A) => boolean
},
): boolean {
const { valueEqual } = options
const valueEqual = options?.valueEqual || ((x, y) => x === y)

const equal = (x: Belief<A>, y: Belief<A>) =>
beliefEqual(x, y, { valueEqual })
Expand Down
8 changes: 5 additions & 3 deletions src/belief/beliefEqual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { type Belief } from "./index.js"
export function beliefEqual<A>(
x: Belief<A>,
y: Belief<A>,
options: {
valueEqual: (x: A, y: A) => boolean
options?: {
valueEqual?: (x: A, y: A) => boolean
},
): boolean {
return options.valueEqual(x.value, y.value) && setEqual(x.reasons, y.reasons)
const valueEqual = options?.valueEqual || ((x, y) => x === y)

return valueEqual(x.value, y.value) && setEqual(x.reasons, y.reasons)
}
9 changes: 0 additions & 9 deletions src/examples/barometer-belief-system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,6 @@ test("examples / barometer-belief-system", async () => {
beliefEqual(
beliefSystemQuery(buildingHeight.content) as Belief<any>,
Belief(45, ["superintendent"]),
{
valueEqual: (x, y) => x === y,
},
),
)

Expand All @@ -295,9 +292,6 @@ test("examples / barometer-belief-system", async () => {
beliefEqual(
beliefSystemQuery(buildingHeight.content) as Belief<any>,
Belief(45, ["superintendent"]),
{
valueEqual: (x, y) => x === y,
},
),
)

Expand Down Expand Up @@ -437,9 +431,6 @@ test("examples / barometer-belief-system", async () => {
beliefEqual(
beliefSystemQuery(buildingHeight.content) as Belief<any>,
Belief(theMergeConflict, ["pressure", "superintendent"]),
{
valueEqual: (x, y) => x === y,
},
),
)

Expand Down

0 comments on commit 6824936

Please sign in to comment.