Clojure Memoize Side Effects

· 28 words · 1 minute read

The following is a trick to make a function only exhibit its side effects once.

(def warn-once
  (memoize
    (fn []
      (prn "Hello Warning"))))

(warn-once)
;; "Hello Warning"
(warn-once)