Skip to content

Instantly share code, notes, and snippets.

Created September 12, 2011 04:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/1210561 to your computer and use it in GitHub Desktop.
Save anonymous/1210561 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