Skip to content

Instantly share code, notes, and snippets.

@emanon-was
Created December 29, 2015 02:44
Show Gist options
  • Select an option

  • Save emanon-was/466fb098bfc982aa4a7e to your computer and use it in GitHub Desktop.

Select an option

Save emanon-was/466fb098bfc982aa4a7e to your computer and use it in GitHub Desktop.
(defmacro -> (x &rest forms)
(if (null forms) x
(let ((head (car forms)))
(cond ((listp head)
`(-> (,(car head) ,x ,@(cdr head)) ,@(cdr forms)))
((symbolp head)
`(-> (,head ,x) ,@(cdr forms)))
(t
`(-> ,head ,@(cdr forms)))))))
(defmacro ->> (x &rest forms)
(if (null forms) x
(let ((head (car forms)))
(cond ((listp head)
`(->> (,@head ,x) ,@(cdr forms)))
((symbolp head)
`(->> (,head ,x) ,@(cdr forms)))
(t
`(->> ,head ,@(cdr forms)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment