- Find
nth
element in a collection
(defn nth [arr n]
((comp last (partial take (inc n))) arr))
Using recursion approach
(defn nth [arr n]
(if (= n 0)
(first arr)
(nth (rest arr) (- n 1))))
Lazy Fibonacci sequence
(defn fib [n]
(take n (map first
(iterate
(fn [[a b]] [b (+ a b)])
[1 1]))))