This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
Hi! is there a clojure core predicate for whether something is an immutable, serializable value? Should return true for maps, numbers, keywords, symbols, vectors, and should return false for channels, database connections, files.
No there is no such a function. Technically it's possible to have a Clojure map that holds a java HashMap inside which is mutable. You can create a protocol IMutable with a single is-mutable? method and extend it for Keyword, Symbol, PersistentVector and so on. And for Object (default), the result would be false.
Maybe you can (attempt to) read it as an edn literal? Not sure if that's what you need though.
> Maybe you can (attempt to) read it as an edn literal? Not sure if that’s what you need though.
That gives me a performance penalty I’d like to avoid. I want to keep only serializable, immutable values from a HTTP request map. I thought I could use a https://clojuredocs.org/clojure.walk (probably clojure.walk/postwalk
) to achieve that, but then I’d need a predicate function for which values to keep!
I was hoping for a fast whitelist of values—I’m hesitant to try to serialize and deserialize each value. Though it does sound like a fun exercise :thinking_face:
@U7KDU667Q decided to give your idea a shot, “why optimize before we know we need to?“. Seems to work kind of nice! Though I suspect it won’t perform super well.
This is just off the top of my head, need to think about edge cases :) I'm not signing anything!