Context: let's create a percent encoder. So, characters will be encoded to theirs % representations. Also, I would like vector of string will be encoded like this: [a b] -> (str (encode a) "+" (encode b)). The reason behind is I want spaces be encoded to %20 for strings and lists of strings cat-ed with +. I made this using protocols:
(defprotocol IUrlEncodable
(^String url-encode [v]))
(extend-protocol IUrlEncodable
String
;; Do I need type here? I have it in the protocol.
(^String url-encode [v]
(-> v URLEncoder/encode (.replace "+" "%20")))
IPersistentVector
;; Same question here.
(^String url-encode [v]
(->> v (map url-encode) (join "+"))))
Is it a canonical way to do it? Did I made right thing? What are alternatives? Do I need to redeclare type hint in protocol extension, if I have declared it in the protocol?