Skip to content

Instantly share code, notes, and snippets.

@amalloy
Created July 27, 2012 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amalloy/3186665 to your computer and use it in GitHub Desktop.
Save amalloy/3186665 to your computer and use it in GitHub Desktop.
(defn carry-over [coll]
(reductions (fn [[x :as xs] ys]
(update-in ys [0] (fn [y]
(or (not-empty y) x))))
coll))
user> (carry-over '(["fresh" :hello :world] ["" :foo :bar] ["" :bar :baz] ["cool" :qux :qex] ["" :etc :etc]))
(["fresh" :hello :world] ["fresh" :foo :bar] ["fresh" :bar :baz] ["cool" :qux :qex] ["cool" :etc :etc])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment