clj-kondo flags this: (set/difference #{:a :b} (keys {:a 1}))
but it actually does work. That seq from keys
can be used like a set
@kevin842 this is undeterministic behavior.
(instance? java.util.Set (keys {:a 1}))
false
E.g. this will crash:
user=> (set/difference #{:a :b} (keys {:a 1 :b 2 :c 3}))
Execution error (IllegalArgumentException) at user/eval7 (REPL:1).
contains? not supported on type: clojure.lang.APersistentMap$KeySeq
oh, interesting! I wonder why that is the case.. isn't it just a view over the actual collection, which it knows to support o(1) access?
I must be thinking of python, where dict.keys() does return a set-like view:
>>> "b" in {"a": 1, "b": 2}.keys() True
in any case not relevant to this channel :)@kevin842 this happens because set/difference checks which input is larger and uses that to make things faster
same for union, etc
so never use those fns with something else than sets