Skip to content

Instantly share code, notes, and snippets.

@sundarj
Last active June 6, 2018 23:36
Show Gist options
  • Save sundarj/755ada7d29bd02aa063c25821b4c4d1f to your computer and use it in GitHub Desktop.
Save sundarj/755ada7d29bd02aa063c25821b4c4d1f to your computer and use it in GitHub Desktop.
(defn depth [coll]
(count (->> coll
(tree-seq coll? identity)
(filter coll?))))
(defn comp-times [n f]
(reduce comp
f
(repeat (dec n) f)))
(let [coll [[[1 2 3]]]
the-depth (dec (depth coll))
xform (comp (comp-times the-depth cat)
(map inc))
uncat (comp-times the-depth vector)
rf (completing conj uncat)]
(transduce xform rf coll))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment