Some of my code is generated from Clojure data with fipp
:
And I got:
(defn read-next [db op-data sid op-id op-time]
(let [book-id op-data
user-id (get-in db [:sessions sid :user-id])
book-content (get books-cache book-id)]
(update-in
db
[:users user-id :readings book-id]
(fn [reading]
(if (< (:progress reading) (dec (count book-content)))
(-> reading
(update :progress inc)
(update
:messages
(fn [messages]
(assoc
messages
op-id
(merge
schema/message
{:kind :content,
:text (get book-content (:progress reading)),
:time op-time,
:id op-id,
:book-index (:progress reading)})))))
(do (println "Already finished book") reading))))))
It appears to me the code is not optimal since the content looks like being pushed from right to left. I know it’s because I added {:width 92}
in my code. I could increase the number, but it won’t always solve the problem.
I chose fipp
since it was quite fast and it allowed to generate code from lists and symbols created by my own. Anything to do today if I want the code to be more like human-written?