Skip to content

Instantly share code, notes, and snippets.

@domgetter
Last active January 7, 2016 03:23
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 domgetter/02fbe16020dd8b481d83 to your computer and use it in GitHub Desktop.
Save domgetter/02fbe16020dd8b481d83 to your computer and use it in GitHub Desktop.
(defn words-rows-reducer [row-length [full pending] word]
(let [total-chars-of-word-and-pending (apply + (count word) (map count pending)) ; this could be fancier, taking into account space width and individual letter width
adding-word-would-overflow-row (> total-chars-of-word-and-pending row-length)
store-pending-and-make-new-row (delay [(conj full pending) [word]])
add-word-to-pending (delay [full (conj pending word)])]
(if adding-word-would-overflow-row
@store-pending-and-make-new-row
@add-word-to-pending)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment