Skip to content

Commit

Permalink
coercing(toSupported, f)
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Jun 24, 2024
1 parent 7955785 commit 7035844
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

> - https://github.com/cicada-lang/propagator/issues/2
`coercing(toSupported, f)`
测试反向运算的 provenance
test about "a justified-intervals anomaly"

Expand Down
5 changes: 5 additions & 0 deletions src/dependency/Supported.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ export function Supported<T>(value: T, supports: Set<string>): Supported<T> {
export function isSupported(x: any): x is Supported<any> {
return isNonNullObject(x) && x["@type"] === "Supported"
}

export function toSupported(x: any): Supported<any> {
if (isSupported(x)) return x
return Supported(x, new Set())
}
19 changes: 14 additions & 5 deletions src/merge/merge.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { isNothing } from "../cell/index.js"
import { Supported, isSupported, supportedMerge } from "../dependency/index.js"
import {
isSupported,
supportedMerge,
toSupported,
} from "../dependency/index.js"
import { defineGeneric, defineHandler } from "../generic/index.js"
import {
intervalContainsNumber,
Expand All @@ -8,6 +12,7 @@ import {
intervalIsEmpty,
isInterval,
} from "../interval/index.js"
import { coercing } from "../utils/coercing.js"
import { isNumber } from "../utils/isNumber.js"
import { log } from "../utils/log.js"
import { theMergeConflict } from "./MergeConflict.js"
Expand Down Expand Up @@ -85,9 +90,13 @@ function isSimple(x: any): boolean {
}

defineHandler(merge, [isSupported, isSupported], supportedMerge)
defineHandler(merge, [isSimple, isSupported], (v, m) =>
supportedMerge(Supported(v, new Set()), m),
defineHandler(
merge,
[isSimple, isSupported],
coercing(toSupported, supportedMerge),
)
defineHandler(merge, [isSupported, isSimple], (m, v) =>
supportedMerge(m, Supported(v, new Set())),
defineHandler(
merge,
[isSupported, isSimple],
coercing(toSupported, supportedMerge),
)

0 comments on commit 7035844

Please sign in to comment.