aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorColin Okay <okay@toyful.space>2021-02-22 07:42:23 -0600
committerColin Okay <okay@toyful.space>2021-02-22 07:42:23 -0600
commit2880fc9afedd5141cd1a7f87b75a575189008cc3 (patch)
tree85f1c52db29d6b4095245014a1792efdeb740d81
parent9e7fa2d4fc3dee0208c48fe58e445c58511f7be6 (diff)
added sectiona bout resumables to tutorial
-rw-r--r--README.md26
1 files changed, 26 insertions, 0 deletions
diff --git a/README.md b/README.md
index 8020d04..984eb8e 100644
--- a/README.md
+++ b/README.md
@@ -423,7 +423,33 @@ letting you not have to think about how generators work.
You need only remember the rule: Generators Are Consumed At Most Once.
+### But Resumable Generators are Possible
+An exception to the above comes in the form of *resumable* generators.
+To make a resumable generator call `(make-resumable! <gen>)` on a
+generator. Once you have passed a resumable generator to a consuming
+form you can still get some values out of it by passing it to
+`resume!`, which will create a brand new generator that picks up where
+the old one left off.
+
+E.g.
+
+``` lisp
+
+> (defvar *resumable-evens*
+ (make-resumable! (filter! 'evenp (range :from 1))))
+*RESUMABLE-EVENS*
+
+> (take 10 *resumable-evens* )
+(2 4 6 8 10 12 14 16 18 20)
+
+> (setf *resumable-evens* (resume! *resumable-evens*))
+#<RESUMABLE-GENERATOR! {10049A7F63}>
+
+> (take 10 *resumable-evens*)
+(22 24 26 28 30 32 34 36 38 40)
+
+```
### The Accumulating Consumer