I have hash-maps and I'm trying to get the intersection between the keys. But the function 'intersection' just work with sets.
So I'm getting the keys, transforming the keys to sets and then calling the intersection, something like this:
(intersection (set (keys map-1)) (set (keys map-2)))
There are a better way to do that?
Thanks
This may be the most straightforward / concise way to do it, and it doesn't require building any sets (which is relatively expensive).
(keys (select-keys map-1 (keys map-2)))
Finally, an optimized version, which is a bit faster, and a bit harder to read:
(keep #(some->> % (find map-1) key) (keys map-2))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With