Conformance: reify falls back to a protocol's default extension (jolt-az9a)
A reify that doesn't implement a given protocol method now dispatches to that protocol's extended impls over the reify's host tags (e.g. an Object/default extension) instead of erroring 'No reified method'. This is malli's pattern: it reifies some protocols and relies on RegexSchema's default for the rest. A method with neither a reify impl nor a default still errors.
This commit is contained in:
parent
47864403e8
commit
f30a517cf7
2 changed files with 12 additions and 1 deletions
|
|
@ -240,7 +240,16 @@
|
|||
((reified-methods obj)
|
||||
=> (lambda (rm) (let ((f (hashtable-ref rm method-name #f)))
|
||||
(if f (apply jolt-invoke f obj rest)
|
||||
(error #f (string-append "No reified method " method-name))))))
|
||||
;; not implemented on the reify — fall back to the
|
||||
;; protocol's extended impls over the reify's host tags
|
||||
;; (e.g. an Object/default extension). malli reifies some
|
||||
;; protocols and relies on a protocol's default for the
|
||||
;; rest (jolt-az9a).
|
||||
(let loop ((tags (value-host-tags obj)))
|
||||
(cond ((null? tags) (error #f (string-append "No reified method " method-name)))
|
||||
((find-protocol-method (car tags) proto-name method-name)
|
||||
=> (lambda (g) (apply jolt-invoke g obj rest)))
|
||||
(else (loop (cdr tags)))))))))
|
||||
(else
|
||||
(let loop ((tags (value-host-tags obj)))
|
||||
(cond ((null? tags) (error #f (string-append "No method " method-name " in " proto-name)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue