Fork me on GitHub
#biff
<
2024-05-28
>
jf07:05:57

I just tried to do some debug prints in channel-page (from https://biffweb.com/docs/tutorial/messages/)... and I was expecting / hoping to be able to see the messages that are pulled from the db. However, try as I might, I cannot get anything to print:

(defn channel-page [{:keys [biff/db community channel] :as ctx}]
   (let [messages (q db
                 '{:find (pull message [*])
                   :in [channel]
                   :where [[message :message/channel channel]]}
                 (:xt/id channel))]
     (for [m messages] (prn m))
     (map prn messages)
     (map println messages)
     ...
 )
I understand from printing out (type messages) that it is a clojure.lang.LazySeq... which is fine, but how do I pull out the messages right there in channel-page?

Jacob O'Bryant12:05:13

it's because for and map both return lazy sequences, and since those sequences aren't getting consumed anywhere, the prints never run. when you need to produce side effects (like prints), you can instead use doseq (instead of for) or run! (instead of map).

🙏 1