Skip to content

Instantly share code, notes, and snippets.

@hozumi
Created March 25, 2011 11:53
Show Gist options
  • Save hozumi/886748 to your computer and use it in GitHub Desktop.
Save hozumi/886748 to your computer and use it in GitHub Desktop.
(defmacro _->
([x] x)
([x form] (if (seq? form)
(if (seq-utils/includes? form '_)
(with-meta `(~@(replace {'_ x} form)) (meta form))
(with-meta `(~(first form) ~x ~@(next form)) (meta form)))
(list form x)))
([x form & more] `(_-> (_-> ~x ~form) ~@more)))
;-> and _-> are almost the same behavior until _ is specified.
(_-> {} (assoc :a 1) seq)
;=> ([:a 1])
; Insert expr in arbitrary place by marking _.
(_-> "abcdef" (map int _) (apply hash-map _) (assoc _ 99 :d))
;=> {97 98, 99 :d, 101 102}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment