Permalink
Browse files

Added coercions for keywords and symbols

  • Loading branch information...
weavejester committed Apr 15, 2012
1 parent 6e4e185 commit 2dfbf8cfb8026701461a0565c5eda0ec57d09e90
Showing with 12 additions and 1 deletion.
  1. +12 −1 src/coercer/core.clj
View
@@ -1,5 +1,5 @@
(ns coercer.core
- (:import clojure.lang.Keyword))
+ (:import [clojure.lang Keyword Symbol]))
(defmulti coerce
"Multimethod to convert a value x to a type t."
@@ -29,5 +29,16 @@
(defmethod coerce [String Keyword] [s _]
(keyword s))
+(defmethod coerce [Object Keyword] [x _]
+ (-> (coerce x String)
+ (coerce Keyword)))
+
+(defmethod coerce [String Symbol] [s _]
+ (symbol s))
+
+(defmethod coerce [Object Symbol] [x _]
+ (-> (coerce x String)
+ (coerce Keyword)))
+
(defmethod coerce [Object String] [x _]
(.toString x))

0 comments on commit 2dfbf8c

Please sign in to comment.