aboutsummaryrefslogtreecommitdiff
path: root/samples/state_writer.js
diff options
context:
space:
mode:
Diffstat (limited to 'samples/state_writer.js')
-rw-r--r--samples/state_writer.js13
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})))