|
6153 | 6153 | (let [impl-method-arities (get impl-method-arity-map proto-method-name)]
|
6154 | 6154 | (when (not= impl-method-arities proto-method-arities)
|
6155 | 6155 | (throw (ex-info "target-type must implement all protocol method arities"
|
6156 |
| - {:proto-method proto-method-name |
| 6156 | + {:proto-method proto-method-name |
6157 | 6157 | :proto-method-arities proto-method-arity-map
|
6158 |
| - :impl-method-arities impl-method-arity-map |
6159 |
| - :missing-arities (->> proto-method-arities |
6160 |
| - (remove impl-method-arities) |
6161 |
| - (set))})))))) |
| 6158 | + :impl-method-arities impl-method-arity-map |
| 6159 | + :missing-arities (->> proto-method-arities |
| 6160 | + (remove impl-method-arities) |
| 6161 | + (set))})))))) |
6162 | 6162 | (doseq [method-def method-map
|
6163 | 6163 | :let [[method-name fn] method-def]]
|
6164 | 6164 | (let [dispatch-method (get proto-methods method-name)]
|
|
6196 | 6196 | "Convert a vector of method definitions (as expected by ``extend-protocol`` and
|
6197 | 6197 | ``extend-type``\\) into a map of method definitions which can be passed to
|
6198 | 6198 | ``extend``\\."
|
6199 |
| - [methods] |
| 6199 | + [target-type methods] |
6200 | 6200 | (->> (group-by first methods)
|
6201 | 6201 | (reduce (fn [m [method-name arities]]
|
6202 |
| - (->> (map rest arities) |
6203 |
| - (apply list `fn) |
6204 |
| - (assoc! m (keyword (name method-name))))) |
| 6202 | + (let [genned-method-name (symbol |
| 6203 | + (str (name method-name) |
| 6204 | + "-" |
| 6205 | + (if (nil? target-type) |
| 6206 | + "nil" |
| 6207 | + (name target-type))))] |
| 6208 | + (->> (map rest arities) |
| 6209 | + (apply list `fn genned-method-name) |
| 6210 | + (assoc! m (keyword (name method-name)))))) |
6205 | 6211 | (transient {}))
|
6206 | 6212 | (persistent!)))
|
6207 | 6213 |
|
|
6246 | 6252 | `(do ~@(map (fn [[target-type methods]]
|
6247 | 6253 | `(extend ~target-type
|
6248 | 6254 | ~proto
|
6249 |
| - ~(extend-map methods))) |
| 6255 | + ~(extend-map target-type methods))) |
6250 | 6256 | (sym-and-method-groups specs))))
|
6251 | 6257 |
|
6252 | 6258 | (defmacro extend-type
|
|
6281 | 6287 | [target-type & specs]
|
6282 | 6288 | `(extend ~target-type
|
6283 | 6289 | ~@(mapcat (fn [[proto methods]]
|
6284 |
| - [proto (extend-map methods)]) |
| 6290 | + [proto (extend-map target-type methods)]) |
6285 | 6291 | (sym-and-method-groups specs))))
|
6286 | 6292 |
|
6287 | 6293 | (defn extenders
|
|
0 commit comments