diff options
author | Marvin Borner | 2024-11-27 02:12:12 +0100 |
---|---|---|
committer | Marvin Borner | 2024-11-27 02:27:48 +0100 |
commit | 6da602b0a29afcd2aa15725547375a80e30b3983 (patch) | |
tree | bb268dc7935696c2687c4ec151c2e0108536fa6f /samples/state_writer.js |
initial commit
Diffstat (limited to 'samples/state_writer.js')
-rw-r--r-- | samples/state_writer.js | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/samples/state_writer.js b/samples/state_writer.js new file mode 100644 index 0000000..081e9f1 --- /dev/null +++ b/samples/state_writer.js @@ -0,0 +1,13 @@ +import * as state from '../src/state.js' + +const log = (a, str) => st => state.State(a)(st + str) + +const deepthought = state.DO(function* () { + const answer = yield log(42, "Finding answer... ") + const correct = yield log(answer == 42, "Checking answer... ") + if (correct) yield log(null, "Is correct!") + else yield log(null, "Is false!") + return answer +}) + +console.log(deepthought("")(log => answer => ({answer, log}))) |