Refund seqs:
user> (take-while seq (iterate rest [1 2 3]))
([1 2 3] (2 3) (3))
Return vectors:
user> (take-while seq (iterate #(subvec % 1) [1 2 3]))
([1 2 3] [2 3] [3])
I saw this template packaged in a function iterate-whilethat is almost the same as your function nest:
(defn iterate-while [pred f x]
(take-while pred (iterate f x)))
Please note that is (seq x)equivalent, and preferable,(not (empty? x))
source
share