Permalink
Browse files

defmethod -> case

  • Loading branch information...
1 parent 70ffaab commit 06c0d1261bebbac90ec95987cc910b2fd3aee7ba Alex Baranosky committed Dec 23, 2012
Showing with 19 additions and 28 deletions.
  1. +12 −17 src/slam/hound/regrow.clj
  2. +7 −11 src/slam/hound/stitch.clj
View
@@ -43,23 +43,18 @@
(finally
(remove-ns (.name *ns*)))))))
-(defmulti candidates (fn [type missing] type))
-
-(defmethod candidates :import [type missing]
- (for [class-name search/available-classes
- :when (= missing (last (.split class-name "\\.")))]
- (symbol class-name)))
-
-(defmethod candidates :require [type missing]
- (for [n (all-ns)
- :when (= missing (last (.split (name (ns-name n)) "\\.")))]
- [(ns-name n) :as (symbol missing)]))
-
-(defmethod candidates :use [type missing]
- (for [n (all-ns)
- [sym var] (ns-publics n)
- :when (= missing (name sym))]
- [(ns-name n) :only [sym]]))
+(defn candidates [type missing]
+ (case type
+ :import (for [class-name search/available-classes
+ :when (= missing (last (.split class-name "\\.")))]
+ (symbol class-name))
+ :require (for [n (all-ns)
+ :when (= missing (last (.split (name (ns-name n)) "\\.")))]
+ [(ns-name n) :as (symbol missing)])
+ :use (for [n (all-ns)
+ [sym var] (ns-publics n)
+ :when (= missing (name sym))]
+ [(ns-name n) :only [sym]])))
(defn- butlast-regex [candidate]
(if (symbol? candidate)
View
@@ -19,24 +19,20 @@
[namespace :only (vec (sort (for [[_ _ [var]] subclause]
var)))]))
-(defmulti collapse-clause (comp second list))
-
-(defmethod collapse-clause :import [ns-map clause]
- (update-in ns-map [:import] group-by-package))
-
-(defmethod collapse-clause :require [ns-map clause]
- ns-map)
-
-(defmethod collapse-clause :use [ns-map clause]
- (update-in ns-map [:use] group-by-namespace))
+(defn collapse-clause [ns-map clause]
+ (case clause
+ :use (update-in ns-map [:use] group-by-namespace)
+ :import (update-in ns-map [:import] group-by-package)
+ ns-map))
(defn- collapse-clauses [ns-map]
(reduce collapse-clause ns-map ns-clauses))
(defn sort-subclauses [ns-map]
;; lists aren't comparable? huh?
(reduce #(update-in %1 [%2] (partial sort-by str))
- ns-map ns-clauses))
+ ns-map
+ ns-clauses))
(defn ns-from-map [ns-map]
`(~'ns ~(:name ns-map)

0 comments on commit 06c0d12

Please sign in to comment.