Takes a function of no args, presumably with side effects, and
returns an infinite (or length n if supplied) lazy sequence of calls
to it
;these two functions are equivalent user=> (take 5 (repeatedly #(rand-int 11))) (6 6 3 9 8) user=> (repeatedly 5 #(rand-int 11)) (1 8 6 9 6) ;compare with repeat user=> (repeat 5 (int (rand 100))) (94 94 94 94 94)
(defn repeatedly
"Takes a function of no args, presumably with side effects, and
returns an infinite (or length n if supplied) lazy sequence of calls
to it"
{:added "1.0"
:static true}
([f] (lazy-seq (cons (f) (repeatedly f))))
([n f] (take n (repeatedly f))))
Comments top
No comments for repeatedly. Log in to add a comment.