(defn lisptype [x]
(cond
(list? x) list
(vector? x) vector
(map? x) hash-map
(string? x) (fn [& x] (clojure.string/join x))
true list))
(defn rotate [n coll]
(let [at (if (neg? n) (Math/abs n) (- (count coll) n))
[left right] (split-at at coll)]
(apply (lisptype coll) (concat right left))))
※ map …
clojure `type function` Java clojure (list vector)…
(apply (type coll) (concat right left))
:
rizaudo lisptype function map array-map set Are there sets that keep the insertion order? order-preserving-set function ()
(defn lisptype [x]
(cond
(list? x) list
(vector? x) vector
(set? x) order-preserving-set
(map? x) (fn [& x] (apply array-map (flatten x)))
(string? x) (fn [& x] (clojure.string/join x))
:else list))
rotate function set order-preserving-set function