Artificial intelligent assistant

Clojureの関数で渡されたものと同じ型のコレクションを返すには? (defn rotate [n coll] (let [at (if (neg? n) (Math/abs n) (- (count coll) n)) [left right] (split-at at coll)] (concat right left))) (defmulti vomit (fn [coll] (if (list? coll) :list (if (vector? coll) :vector))) :default nil) (defmethod vomit :list [coll] (partial apply list)) (defmethod vomit :vector [coll] (partial into (empty coll))) (defmethod vomit nil [coll] identity) (defn rotate [n coll] (let [at (if (neg? n) (Math/abs n) (- (count coll) n)) [left right] (split-at at coll)] ((vomit coll) (concat right left))))




(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

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 783bfbbb1cdec1acba7648c225b5a190