mount

ben 2018-06-01T10:04:58.000235Z

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
  [x]
  (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 
  [f]
  (map f my-seq))

ben 2018-06-01T10:05:48.000039Z

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

2018-06-01T10:08:29.000120Z

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

2018-06-01T10:09:38.000193Z

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 🙂

2018-06-01T10:09:44.000162Z

you could do this in the REPL:

2018-06-01T10:09:59.000103Z

(mount/start)
(def my-function1 (my-function-maker my-seq))

ben 2018-06-01T10:24:19.000143Z

Thanks, Timo - that's really helpful 👍

2018-06-01T10:24:38.000038Z

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

2018-06-01T10:24:43.000387Z

glad to help :thumbsup:

ben 2018-06-01T10:26:06.000037Z

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

2018-06-01T10:26:52.000435Z

not a good phrasing tbh

ben 2018-06-01T10:37:05.000224Z

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

ben 2018-06-01T10:37:13.000432Z

it's a good phrasing!