Skip to content

Commit

Permalink
Add the cycle and cycle-with functions.
Browse files Browse the repository at this point in the history
These create lazy, infinite lists by taking an initial seed list and extending it over and over. Cycle just repeats it, cycle-with uses a function on the previous seed to get the next one.
  • Loading branch information
Scriptor committed Jan 13, 2012
1 parent 3dc74c5 commit cd58a93
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lang.phn
Expand Up @@ -129,6 +129,14 @@
(fn seq-join (xs [glue ""])
(implode glue (arr xs)))

(fn cycle (xs)
(lazy (concat xs (cycle xs))))

(fn cycle-with (f xs)
(lazy
(let [new-xs (map f xs)]
(concat xs (cycle-with f new-xs)))))

(fn vals (m)
(array-values (arr m)))

Expand Down

0 comments on commit cd58a93

Please sign in to comment.