Fork me on GitHub

Hi all! I attempted to do some refactoring on a project using mount, and I've found that passing a mount.core.DerefableState to a higher order function in order to make a new function results in an error being thrown when that new function is called. I've attempted to display what I mean here 👇

(defstate my-seq :start (load-my-seq ...))

(defn my-function-maker
  (fn [f] (map f x)))

;; Doesn't work when called
;; "Don't know how to create ISeq from: mount.core.DerefableState"
(def my-function1 (my-function-maker my-seq))

;; Works okay
(defn my-function2 
  (map f my-seq))


Does anyone have any insight into why this is the case? Or where in the documentation I should be looking - I've had no luck so far

Timo Freiberg10:06:29

the my-seq state starts off uninitialized (as a mount.core.DerefableState). after calling mount/start, the :start function will be called, (load-my-seq ...) in this case, and my-seq will be set to the return value of that function

Timo Freiberg10:06:38

you don't want compile-time dependencies to the value of runtime states anyway, so what you're doing in my-function1 should hopefully never be necessary 🙂

Timo Freiberg10:06:44

you could do this in the REPL:

Timo Freiberg10:06:59

(def my-function1 (my-function-maker my-seq))


Thanks, Timo - that's really helpful 👍

Timo Freiberg10:06:38

so the problem is not the higher order function, but that you're calling it in a def

Timo Freiberg10:06:43

glad to help :thumbsup:


Yep - when you phrase it as compile-time dependencies to the value of runtime states it does sound quite bad, doesn't it?

Timo Freiberg10:06:52

not a good phrasing tbh


haha no I meant it really highlights why what I was doing is bad


it's a good phrasing!