|
1470 | 1470 | (recur (conj seen fname) (next methods)))))
|
1471 | 1471 | (recur (conj protos proto) impls)))))
|
1472 | 1472 |
|
| 1473 | +(core/defn- type-hint-first-arg |
| 1474 | + [type-sym argv] |
| 1475 | + (assoc argv 0 (vary-meta (argv 0) assoc :tag type-sym))) |
| 1476 | + |
| 1477 | +(core/defn- type-hint-single-arity-sig |
| 1478 | + [type-sym sig] |
| 1479 | + (list* (first sig) (type-hint-first-arg type-sym (second sig)) (nnext sig))) |
| 1480 | + |
| 1481 | +(core/defn- type-hint-multi-arity-sig |
| 1482 | + [type-sym sig] |
| 1483 | + (list* (type-hint-first-arg type-sym (first sig)) (next sig))) |
| 1484 | + |
| 1485 | +(core/defn- type-hint-multi-arity-sigs |
| 1486 | + [type-sym sigs] |
| 1487 | + (list* (first sigs) (map (partial type-hint-multi-arity-sig type-sym) (rest sigs)))) |
| 1488 | + |
| 1489 | +(core/defn- type-hint-sigs |
| 1490 | + [type-sym sig] |
| 1491 | + (if (vector? (second sig)) |
| 1492 | + (type-hint-single-arity-sig type-sym sig) |
| 1493 | + (type-hint-multi-arity-sigs type-sym sig))) |
| 1494 | + |
| 1495 | +(core/defn- type-hint-impl-map |
| 1496 | + [type-sym impl-map] |
| 1497 | + (reduce-kv (core/fn [m proto sigs] |
| 1498 | + (assoc m proto (map (partial type-hint-sigs type-sym) sigs))) |
| 1499 | + {} impl-map)) |
| 1500 | + |
1473 | 1501 | (core/defmacro extend-type
|
1474 | 1502 | "Extend a type to a series of protocols. Useful when you are
|
1475 | 1503 | supplying the definitions explicitly inline. Propagates the
|
|
1500 | 1528 | _ (validate-impls env impls)
|
1501 | 1529 | resolve (partial resolve-var env)
|
1502 | 1530 | impl-map (->impl-map impls)
|
| 1531 | + impl-map (if ('#{boolean number} type-sym) |
| 1532 | + (type-hint-impl-map type-sym impl-map) |
| 1533 | + impl-map) |
1503 | 1534 | [type assign-impls] (core/if-let [type (base-type type-sym)]
|
1504 | 1535 | [type base-assign-impls]
|
1505 | 1536 | [(resolve type-sym) proto-assign-impls])]
|
|
0 commit comments