forked from camsaul/methodical
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Move Describable to methodical.interface
- Loading branch information
Abhinav Omprakash
committed
Oct 18, 2022
1 parent
d65f076
commit 257cb48
Showing
20 changed files
with
258 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,89 @@ | ||
(ns methodical.impl.method-table.clojure | ||
(:require | ||
[clojure.core.protocols :as clojure.protocols] | ||
[methodical.impl.method-table.common :as method-table.common] | ||
[methodical.interface] | ||
[methodical.util.describe :as describe] | ||
[pretty.core :as pretty]) | ||
[clojure.core.protocols :as clojure.protocols] | ||
[methodical.impl.method-table.common :as method-table.common] | ||
[methodical.interface :as i] | ||
[pretty.core :as pretty]) | ||
(:import | ||
(methodical.interface MethodTable))) | ||
(methodical.interface | ||
MethodTable))) | ||
|
||
|
||
(set! *warn-on-reflection* true) | ||
|
||
(comment methodical.interface/keep-me) | ||
|
||
(deftype ClojureMethodTable [m] | ||
|
||
(deftype ClojureMethodTable | ||
[m] | ||
|
||
pretty/PrettyPrintable | ||
(pretty [_] | ||
|
||
(pretty | ||
[_] | ||
(if (seq m) | ||
(list 'clojure-method-table (count m) 'primary) | ||
'(clojure-method-table))) | ||
|
||
|
||
Object | ||
(equals [_ another] | ||
|
||
(equals | ||
[_ another] | ||
(and (instance? ClojureMethodTable another) | ||
(= m (.m ^ClojureMethodTable another)))) | ||
|
||
|
||
MethodTable | ||
(primary-methods [_] | ||
|
||
(primary-methods | ||
[_] | ||
m) | ||
|
||
(aux-methods [_] | ||
|
||
(aux-methods | ||
[_] | ||
nil) | ||
|
||
(add-primary-method [this dispatch-val method] | ||
|
||
(add-primary-method | ||
[this dispatch-val method] | ||
(let [new-m (assoc m dispatch-val method)] | ||
(if (= m new-m) | ||
this | ||
(ClojureMethodTable. new-m)))) | ||
|
||
(remove-primary-method [this dispatch-val] | ||
|
||
(remove-primary-method | ||
[this dispatch-val] | ||
(let [new-m (dissoc m dispatch-val)] | ||
(if (= m new-m) | ||
this | ||
(ClojureMethodTable. new-m)))) | ||
|
||
(add-aux-method [_ _ _ _] | ||
|
||
(add-aux-method | ||
[_ _ _ _] | ||
(throw (UnsupportedOperationException. "Clojure-style multimethods do not support auxiliary methods."))) | ||
|
||
(remove-aux-method [_ _ _ _] | ||
|
||
(remove-aux-method | ||
[_ _ _ _] | ||
(throw (UnsupportedOperationException. "Clojure-style multimethods do not support auxiliary methods."))) | ||
|
||
|
||
clojure.protocols/Datafiable | ||
(datafy [this] | ||
|
||
(datafy | ||
[this] | ||
{:class (class this) | ||
:primary (method-table.common/datafy-primary-methods m)}) | ||
|
||
describe/Describable | ||
(describe [this] | ||
|
||
i/Describable | ||
|
||
(describe | ||
[this] | ||
(format "It uses the method table [[%s]]. These primary methods are known:\n\n%s" | ||
(.getCanonicalName (class this)) | ||
(method-table.common/describe-primary-methods m)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.