Currently with-meta doesn't work for varargs fns (which works in Clojure):
(apply (with-meta #(-> %&) {}) 0 1 2 (range 30))
Given JS is so flexible I'd propose the following implementation of meta fn:
(defn meta-fn [f m] (let [new-f (goog/bind f #js{})] (goog/mixin new-f f) (specify! new-f IMeta (-meta [_] m)) new-f))
The goog/bind creates a copy, and the goog/mixin is just for performance reasons (copy any IFn protocol or applyTo).
Benefits:
Slightly faster
Much simpler and smaller code (the 20 arities of MetaFn are emitted 3 times (.call, .apply, prototype.IFn)
Works with varargs.
Currently with-meta doesn't work for varargs fns (which works in Clojure):
(apply (with-meta #(-> %&) {}) 0 1 2 (range 30))
Given JS is so flexible I'd propose the following implementation of meta fn:
(defn meta-fn [f m] (let [new-f (goog/bind f #js{})] (goog/mixin new-f f) (specify! new-f IMeta (-meta [_] m)) new-f))
The goog/bind creates a copy, and the goog/mixin is just for performance reasons (copy any IFn protocol or applyTo).
Benefits:
Slightly faster
Much simpler and smaller code (the 20 arities of MetaFn are emitted 3 times (.call, .apply, prototype.IFn)
Works with varargs.