Welcome! Please see the About page for a little more info on how this works.

+3 votes
in ClojureScript by
reshown by

I stumbled upon this by accident

Clojure
(get {:x (reduced 10)} :x)
=> #object[clojure.lang.Reduced 0x28494b99 {:status :ready, :val 10}]

(get-in {:x (reduced 10)} [:x])
=> #object[clojure.lang.Reduced 0x28494b99 {:status :ready, :val 10}]

Clojurescript
(get {:x (reduced 10)} :x)
=> #object[cljs.core.Reduced] ; Same behavior as Clojure
(get-in {:x (reduced 10)} [:x])
=> 10

So get-in seems to automatically deref the reduced value in Clojurescript?

1 Answer

0 votes
by

The CLJS implementation of get-in uses reduce in the default case which means that when the reduced object is found in look-up it's unwrapped by the reduce logic. If this is causing error then a temporary work-around would be to provide a not-found value to get-in which will use the same logic as Clojure. I think a ticket to the CLJS team to address this would be a reasonable ask.

by
reshown by
Cool, thanks.
by
I guess that there may be other contexts where reduce is used to process data. So, maybe one cannot count on a `reduced` value to "survive" through a function call?
...