Anonymous avatar Anonymous committed 8a5bcc2

Implement lazy-iterate

Comments (0)

Files changed (2)

 
 (lazy-seq make-lazy-seq
  lazy-seq? lazy-seq-realized?
- lazy-null lazy-null?
+ lazy-null lazy-null? realized-lazy-seq
  lazy-seq->list list->lazy-seq
  lazy-head lazy-tail lazy-append
  lazy-take lazy-drop lazy-ref
  lazy-map lazy-filter lazy-each
- lazy-numbers lazy-repeat lazy-repeatedly
- realized-lazy-seq 
- input-port->lazy-seq)
+ lazy-iterate lazy-repeat lazy-repeatedly
+ lazy-numbers input-port->lazy-seq)
 
 (import chicken scheme)
 (use srfi-1 extras)
                   (cons (lazy-head seq)
                         (loop2 (lazy-tail seq))))))))))
 
+(define (lazy-iterate f x)
+  (lazy-seq
+    (cons x (lazy-iterate f (f x)))))
+
 )
                                    (lazy-numbers count: 2)
                                    (lazy-numbers start: 5)))))
 
+(test-group "lazy-iterate"
+  (test '(2 4 8 16)
+        (lazy-seq->list
+         (lazy-take 4 (lazy-iterate (lambda (x) (* x 2)) 2)))))
+
 (test-exit)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.