Skip to content

Latest commit

 

History

History
27 lines (21 loc) · 423 Bytes

README.md

File metadata and controls

27 lines (21 loc) · 423 Bytes

Clojure examples

  • 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]))))