-
-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can we support a subset of proxy? #550
Comments
A POC: (defn proxy-fn [abstract-class methods]
(case (.getName abstract-class)
"clojure.lang.APersistentMap"
(proxy
[clojure.lang.APersistentMap]
[]
(seq [] ((get methods 'seq)))
(valAt ([k] ((get methods 'valAt) k))
([k d] ((get methods 'valAt) k d))))))
(def m (proxy-fn clojure.lang.APersistentMap
{'seq (fn []
(seq {:a 1 :b 2}))
'valAt (fn
([k] k)
([_k d] d))
'invoke (fn
([k] k))}))
(prn (seq m)) ;; ([:a 1] [:b 2])
(prn (instance? clojure.lang.ILookup m)) ;; true
(prn (get m 1)) 1
(prn (instance? clojure.lang.IFn m)) ;; true
(prn (m 1)) ;; 1 |
borkdude
added a commit
that referenced
this issue
Mar 12, 2021
borkdude
added a commit
that referenced
this issue
Mar 12, 2021
borkdude
added a commit
that referenced
this issue
Mar 12, 2021
This is the code to support it from the babashka side: May need review |
borkdude
added a commit
that referenced
this issue
Mar 13, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Goal: support a subset of proxy, e.g. proxy on APersistentMap like described in this blog post:
https://blog.wsscode.com/guide-to-custom-map-types/
/cc @GreshamDanielStephens @wilkerlucio
The text was updated successfully, but these errors were encountered: