Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save amalloy/1210563 to your computer and use it in GitHub Desktop.

Select an option

Save amalloy/1210563 to your computer and use it in GitHub Desktop.
;; amalloy's solution to Global take-while
;; https://4clojure.com/problem/114
(fn f [n pred coll]
(lazy-seq
(when-let [[x & xs] (seq coll)]
(let [n (if (pred x), (dec n), n)]
(when-not (zero? n)
(cons x (f n pred xs)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment