How fun! I was looking for classes defined within Clojure's core library via deftype
, and noticed for the first time that in the pretty_writer.clj source file that is part of the clojure.pprint implementation, there is a macro called deftype
created in there that is different than clojure.core/deftype
. Fun!
ä
It’s possible I’m conflating it with another language but isn’t there a core function for filtering things with a map?
@jayzawrotny Maybe the map itself is the filter?
It would be for filtering other maps in a collection
It depends on your example. Keywords and maps implement IFn, so you can use them as a filter fn.
Right
(->> [{:color :blue
:size :l}
{:color :red
:size :s}
{:color :green
:size :s}
{:color :purple
:size :s}]
(filter #(where? % {:size :s})))
Not a core function, but sounds a lot like https://github.com/BrunoBonacci/where
#(= :s (:size %))
I also have some submap?
function in some tests but that's not in core
#(= (select-keys %2 (keys %1)) %1)
That’s what I went with noisesmith, I must have been thinking about the submap? predicate that I think Alex posted somewhere once.
In the spec tests
I've been tweaking it for my tests: https://github.com/borkdude/clj-kondo/blob/ca947294b18df2b1049ceca5a29578cee89b037f/test/clj_kondo/test_utils.clj#L15