clojure-koans/src/koans/11_lazy_sequences.clj
Colin Jones 7974120ec3
Use an explicit function argument for iterate
Also replace :hello with "hello" to avoid potential confusion since
:hello is also a function.

refs #75
2017-10-09 13:17:12 -05:00

28 lines
725 B
Clojure

(ns koans.11-lazy-sequences
(:require [koan-engine.core :refer :all]))
(meditations
"There are many ways to generate a sequence"
(= __ (range 1 5))
"The range starts at the beginning by default"
(= __ (range 5))
"Only take what you need when the sequence is large"
(= [0 1 2 3 4 5 6 7 8 9]
(take __ (range 100)))
"Or limit results by dropping what you don't need"
(= [95 96 97 98 99]
(drop __ (range 100)))
"Iteration provides an infinite lazy sequence"
(= __ (take 8 (iterate (fn [x] (* x 2)) 1)))
"Repetition is key"
(= [:a :a :a :a :a :a :a :a :a :a]
(repeat 10 __))
"Iteration can be used for repetition"
(= (repeat 100 "hello")
(take 100 (iterate ___ "hello"))))