fipp icon indicating copy to clipboard operation
fipp copied to clipboard

Strategy to print `goog.math/Long`

Open prabhjots opened this issue 1 year ago • 1 comments

goog.math/Long is not showing up very well

#?(:cljs
   (let [x (goog.math/Long.fromString "123")]
     (with-out-str (fipp/pprint {:test x} {:width 120}))))

It evaluates to the following

"{:test #object[#object[Long]]}\n"

Problem gets fixed by using the IEdn protocol

#?(:cljs
   (extend-protocol IEdn
     goog.math/Long
     (-edn [x]
       (js/Number (.toString ^goog.math/Long x)))))

Is using the IEdn protocol is the right approach for this problem. If yes then please consider documenting the IEdn protocol in the readme.

prabhjots avatar Sep 24 '24 09:09 prabhjots

Yes, IEdn is the right way to do this. I should probably document it.

However, I think you may want to avoid losing precision by doing something like this:

#?(:cljs
   (extend-protocol IEdn
     goog.math/Long
     (-edn [x]
       (tagged-literal 'goog/long (.toString ^goog.math/Long x)))))

brandonbloom avatar Sep 27 '24 23:09 brandonbloom

Closing in favor of https://github.com/brandonbloom/fipp/issues/91

brandonbloom avatar Jul 26 '25 20:07 brandonbloom