Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Jun 23, 2024
1 parent 8e68a03 commit a124ee8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/dependency/supportedMerge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function supportedMerge<A, B>(

if (mergedContent === content.value) {
// 正向和反向的 implies 代表等价。
if (implies(increment, content)) {
if (implies(increment, mergedContent)) {
// 倾向于 content,除非 increment 真的有更多信息。
if (setIsSubsetOf(content.supports, increment.supports)) {
return content
Expand Down
6 changes: 3 additions & 3 deletions src/monad/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ export function naryFmap(
f: (...args: Array<any>) => any,
): (...margs: Array<any>) => any {
return (...margs) => {
function loop(margs: Array<any>, f: (...args: Array<any>) => any): any {
function recur(margs: Array<any>, f: (...args: Array<any>) => any): any {
if (margs.length === 0) return f()

return bind(margs[0], (arg) =>
loop(margs.slice(1), (...restArgs) => f(arg, ...restArgs)),
recur(margs.slice(1), (...restArgs) => f(arg, ...restArgs)),
)
}

return loop(margs, f)
return recur(margs, f)
}
}
11 changes: 7 additions & 4 deletions src/monads/supported-monad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ defineHandler(fmap, [isFunction, isSupported], (f, ma: Supported<any>) =>
Supported(bind(ma.value, f), ma.supports),
)

defineHandler(join, [isSupported], (ma) => ma)
defineHandler(join, [isSupported], (mma) => mma)
defineHandler(
join,
[(ma) => isSupported(ma) && isNothing(ma.value)],
(ma) => nothing,
[(mma) => isSupported(mma) && isNothing(mma.value)],
(mma) => nothing,
)
defineHandler(
join,
[(mma) => isSupported(mma) && isSupported(mma.value)],
(mma) => join(mma.value.value, setUnion(mma.supports, mma.value.supports)),
(mma) =>
join(
Supported(mma.value.value, setUnion(mma.supports, mma.value.supports)),
),
)
16 changes: 8 additions & 8 deletions src/propagator/definePrimitive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,18 @@ export function definePrimitive<A extends number>(
return definition as any as PropagatorDefinitionWithFixedArity<A>
}

function watch(cells: Array<Cell<any>>, propagator: Propagator): void {
for (const cell of cells) {
addPropagator(cell, propagator)
}

schedule([propagator])
}

function lift(
fn: (...args: Array<any>) => MaybePromise<any>,
): (...args: Array<Cell<any>>) => MaybePromise<any> {
fn = naryFmap(fn)

return (...inputs) => fn(...inputs.map((input) => input.content))
}

function watch(cells: Array<Cell<any>>, propagator: Propagator): void {
for (const cell of cells) {
addPropagator(cell, propagator)
}

schedule([propagator])
}

0 comments on commit a124ee8

Please sign in to comment.