Skip to content

Commit

Permalink
propagators/conditional -- conditional & conditionalWriter
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Sep 30, 2024
1 parent fb2d2f0 commit 3f5e0a0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

> https://github.com/cicada-lang/propagator/issues/4
propagators/conditional -- conditional & conditionalWriter
propagators/conditional.test

propagators/constant.test
Expand Down
Empty file.
18 changes: 18 additions & 0 deletions src/propagators/conditional.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { definePropagator } from "../propagator/index.js"
import { inverter, switcher } from "./index.js"

export const conditional = definePropagator(
4,
(control, ifTrue, ifFalse, output) => {
switcher(control, ifTrue, output)
switcher(inverter(control), ifFalse, output)
},
)

export const conditionalWriter = definePropagator(
4,
(control, input, ifTrue, ifFalse) => {
switcher(control, input, ifTrue)
switcher(inverter(control), input, ifFalse)
},
)

0 comments on commit 3f5e0a0

Please sign in to comment.