Moritz Heidkamp avatar Moritz Heidkamp committed 45af739

Implement lazy-length

Comments (0)

Files changed (2)

 (lazy-seq make-lazy-seq
  lazy-seq? lazy-seq-realized? lazy-null? 
  lazy-seq->list list->lazy-seq
- lazy-head lazy-tail lazy-append
+ lazy-head lazy-tail
+ lazy-length lazy-append
  lazy-take lazy-drop lazy-ref
  lazy-take-while lazy-drop-while
  lazy-map lazy-filter lazy-each
        #f (cons (car list)
                 (list->lazy-seq (cdr list))))))
+(define (lazy-length seq)
+  (let loop ((count 0) (seq seq))
+    (if (lazy-null? seq)
+        count
+        (loop (+ count 1) (lazy-tail seq)))))
 (define (lazy-take n seq)
     (if (or (zero? n) (lazy-null? seq))
   (test "ok" (lazy-head (lazy-seq (list->lazy-seq '("ok"))))))
+(test-group "lazy-length"
+  (test 10 (lazy-length (lazy-numbers count: 10))))
 (test-group "lazy-map"
   (test '(1 2 3 4 5)
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
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.