Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
reverse destructuring
(defn put [f x] (let [is-str? (char? (first x)) sx (apply str x)] (cond (map? f) (into {} (map vec (partition 2 (if (even? (count x)) x (conj x nil))))) (vector? f) (if is-str? (conj f sx) (into f x)) (list? f) (if is-str? (cons sx f) (concat f x)) (set? f) (if is-str? #{sx} (into f x)))))
(defn structure [s f] (mapv (fn [b a] (if (empty? b) (put b a) (let [r (structure a b)] (if (vector? b) (vec r) r)))) f (partition-all (int (/ (count s) (count f))) s)))
(structure (range 32) [[[] #{}] [#{} [] []]])
=>
[[[0 1 2 3 4 5 6 7] #{15 13 12 11 9 14 10 8}]
[#{20 17 19 16 18} [21 22 23 24 25] [26 27 28 29 30]]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.