Fork me on GitHub
#specter
<
2017-07-04
>
sophiago22:07:14

Not expecting an answer today, but figured I'd put this out there since I couldn't figure it out from the wiki this weekend: is there a way to just call select on a sequence of keys? I would expect to at least be able to do something like this unless there's a simpler way, but it returns all kv pairs: (select [ALL (fn [[k v]] (map #(= k %) [2 3]))] {1 :a, 2 :b, 3, :c, 4 :d})

sophiago22:07:27

I'm also wondering if, after selecting based on keys, Specter has a faster way to return just the values than val from clojure.core?

nathanmarz22:07:38

@sophiago I think you're looking for (select [(submap [2 3]) MAP-VALS] {1 :a 2 :b 3 :c 4 :d})

nathanmarz22:07:10

or possibly (select (multi-path (keypath 2) (keypath 3)) {1 :a 2 :b 3 :c 4 :d})

sophiago22:07:44

Thanks for responding, Nathan! Probably the first one, unless there's a performance difference?

nathanmarz22:07:01

the latter should be faster

nathanmarz22:07:13

but the former works with a dynamic sequence of keys

sophiago22:07:40

Can't I just map keypath over a sequence of keys?

nathanmarz22:07:17

yes, but that won't perform optimally at the moment

nathanmarz22:07:30

both keypath and multi-path are dynamic navs

sophiago23:07:24

I see. So the fastest way is with submap until that issue is closed?

nathanmarz23:07:52

you'd have to benchmark to be sure, but that would be my guess

sophiago23:07:06

Great. Thanks!

nathanmarz23:07:52

you can do this: (map #(select-any (keypath %) data) key-seq)

nathanmarz23:07:40

if performance is critical just do (map #(get data %) key-seq)

sophiago23:07:14

Ok, got it. I'll run some microbenchmarks to be sure as well.