Lazy seq for Pascal’s triangle in Clojure

Here’s a lazy-seq for Pascal’s triangle:

(ns com.icyrock.clojure.prb.lazy_seq
  (:use clojure.test))

(defn next-pascal-row [prev]
  (concat [1] (map #(apply + %) (map list prev (rest prev))) [1]))

(deftest next-pascal-row-test
  (is (= [1 1] (next-pascal-row [1])))
  (is (= [1 2 1] (next-pascal-row [1 1])))
  (is (= [1 3 3 1] (next-pascal-row [1 2 1])))
  (is (= [1 4 6 4 1] (next-pascal-row [1 3 3 1]))))

(defn lazy-pascal-triangle 
  ([] (lazy-pascal-triangle [1]))
  ([prev] (cons prev 
                (lazy-seq (lazy-pascal-triangle (next-pascal-row prev))))))

(deftest lazy-pascal-triangle-test
  (is (= [[1]
          [1 1]
          [1 2 1]
          [1 3 3 1]
          [1 4 6 4 1]
          [1 5 10 10 5 1]
          [1 6 15 20 15 6 1]]
         (take 7 (lazy-pascal-triangle)))))

(run-tests)