Skip to content

Instantly share code, notes, and snippets.

@jgomo3
Created February 18, 2025 19:30
Show Gist options
  • Save jgomo3/55a940c58910677ae8eafad4dc0e92f2 to your computer and use it in GitHub Desktop.
Save jgomo3/55a940c58910677ae8eafad4dc0e92f2 to your computer and use it in GitHub Desktop.
Thread macros for elements of a collection
(ns map-threads)
(defmacro map-> [coll & body]
`(for [e# ~coll]
(-> e# ~@body)))
(defmacro map->> [coll & body]
`(for [e# ~coll]
(->> e# ~@body)))
(use 'map-threads)
(map-> [1 2 3]
(- 1)
(- 2))
;; => (-2 -1 0)
(map->> [1 2 3]
(- 1)
(- 2))
;; => (2 3 4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment