Skip to content

Instantly share code, notes, and snippets.

@amalloy
Forked from mecdemort/when-lets.clj
Created March 29, 2011 02:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amalloy/891697 to your computer and use it in GitHub Desktop.
Save amalloy/891697 to your computer and use it in GitHub Desktop.
(defmacro when-lets [bindings & body]
(reduce (fn [acc tstform]
`(when-let ~tstform ~acc))
(cons 'do body)
(reverse (map vec (partition 2 bindings)))))
(when-lets [n (first sizes)
s (seq coll)]
(cons (take n coll)
(partitions (next sizes) (drop n coll)))))
(when-let [n (first sizes)]
(when-let [s (seq coll)]
(do (cons (take n coll) (partitions (next sizes) (drop n coll))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment