From 6da602b0a29afcd2aa15725547375a80e30b3983 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Wed, 27 Nov 2024 02:12:12 +0100 Subject: initial commit --- samples/state_writer.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 samples/state_writer.js (limited to 'samples/state_writer.js') 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}))) -- cgit v1.2.3