ghostwheel icon indicating copy to clipboard operation
ghostwheel copied to clipboard

Fix #33: Add >defmethod

Open divs1210 opened this issue 6 years ago • 1 comments

This PR fixes #33

Example:

(defmulti demo pos?)

(>defmethod demo
  true
  [x]
  [pos? => nil?]
  (println "It's positive"))

(>defmethod demo
  false
  [x]
  [(s/or :zero zero? :neg neg?) => nil?]
  (println "It's zero or negative!"))

(demo 1)
;; => "It's positive"

(demo -3)
;; => "It's zero or negative!"

It achieves this by delegating to >defn:

(do
 (>defn demo_G__20347
  [x]
  [pos? => nil?]
  (println "It's positive"))
 (defmethod demo 
   true
   [x]
   (demo_G__20347 x)))

(do
 (>defn demo_G__20352
  [x]
  [(s/or :zero zero? :neg neg?) => nil?]
  (println "It's zero or negative!"))
 (defmethod demo
   false
   [x]
   (demo_G__20352 x)))

divs1210 avatar Feb 02 '20 19:02 divs1210

@divs1210 – I'm necromancing this PR to say thanks and ask if you'd like to resubmit it to the fulcrologic/guardrails repo where all future development of this part of Ghostwheel's functionality will be happening (see the updated README for details).

gnl avatar Feb 17 '24 10:02 gnl

Thanks!

gnl avatar Mar 14 '24 23:03 gnl