Paste number 66351: clojure-java data conversion

Paste number 66351: clojure-java data conversion
Pasted by: drewr
2 months, 3 weeks ago
#clojure | Context in IRC logs
Paste contents:
Raw Source | XML | Display As
(defn clean-db [message]
  (dissoc message :db)
)


(defn to-arraylist [l]
  (let [arraylist (java.util.ArrayList.)]
    (loop [_l l]
      (if _l
        (let [e (first _l)]
          (.add arraylist (convert-type e))
          (recur (rest _l))
)

        arraylist
)
)
)
)


(defn to-hashmap [m]
  (let [hashmap (java.util.HashMap.)]
    (loop [_m m]
      (if _m
        (let [[k v] (first _m)]
          (.put hashmap k (convert-type v))
          (recur (rest _m))
)

        hashmap
)
)
)
)


(defn convert-type [element]
  (cond
   (or (instance? clojure.lang.APersistentMap element)
       (instance? clojure.lang.MapEntry element)
)

   (to-hashmap (clean-db element))
   (or (instance? clojure.lang.APersistentVector element)
       (instance? clojure.lang.PersistentList element)
)

   (to-arraylist element)
   true element
)
)


This paste has no annotations.

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.