Welcome! Please see the About page for a little more info on how this works.

0 votes
in Macros by

It is common to have lambda functions with one argument for things like map, filter, find, etc.

I think could be usefull a macro that do something like (fn-> :value inc (> 1)) which would be equivalent of #(-> % :value inc (> 1))

Something like

(defmacro fn->
  [& forms]
  `(fn [x#] (-> x# ~@forms)))
(defmacro fn->>
  [& forms]
  `(fn [x#] (->> x# ~@forms)))

I see this a very useful for readability if in the core library. wdyt?

1 Answer

0 votes
by

Isn't it shorter to just put the # at the front of your thread expression?

by
is not,
For me looks more readable, noiseless and simple,
But I know that it could be just opinion
by
I don't think there's any interest in adding this to Clojure itself. But the cool thing about Clojure and Lisps is we can all have our preferred syntax. :)
...