Fork me on GitHub
#clojure
<
2020-11-15
>
andy.fingerhut03:11:30

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!

👀 3
jaide16:11:10

It’s possible I’m conflating it with another language but isn’t there a core function for filtering things with a map?

borkdude16:11:07

@jayzawrotny Maybe the map itself is the filter?

jaide16:11:08

It would be for filtering other maps in a collection

borkdude16:11:14

It depends on your example. Keywords and maps implement IFn, so you can use them as a filter fn.

jaide17:11:03

(->> [{:color :blue
       :size :l}
      {:color :red
       :size :s}
      {:color :green
       :size :s}
      {:color :purple
       :size :s}]
     (filter #(where? % {:size :s})))

Emlyn Corrin16:11:53

Not a core function, but sounds a lot like https://github.com/BrunoBonacci/where

borkdude17:11:17

#(= :s (:size %))

borkdude17:11:59

I also have some submap? function in some tests but that's not in core

noisesmith17:11:30

#(= (select-keys %2 (keys %1)) %1)

jaide17:11:00

That’s what I went with noisesmith, I must have been thinking about the submap? predicate that I think Alex posted somewhere once.

borkdude17:11:53

In the spec tests