Fork me on GitHub
#specter
<
2016-05-29
>
luxbock12:05:03

how can I select a subset of keys on a map?

luxbock12:05:36

I thought I could use sets with the keys I'm interested in as the selector but this didn't work, eventhough I see that they implement the protocol

luxbock12:05:28

i.e. (select [#{:foo}] {:foo 1 :bar 2}) returns nil

luxbock12:05:25

what I'm trying to achieve is {:foo 1 :bar 2 :baz 3} => {:foo "1" :bar "2" :baz 3}

nathanmarz12:05:50

@luxbock: You can use either submap or multi-path

nathanmarz12:05:09

(transform (multi-path :foo :bar) str {:foo 1 :bar 2 :baz 3})

nathanmarz12:05:44

(transform [(submap [:foo :bar]) ALL LAST] str {:foo 1 :bar 2 :baz 3})

luxbock14:05:26

do sets serve some other purpose as selectors?

nathanmarz15:05:25

they act as filter predicates

nathanmarz15:05:30

(select [ALL #{1 2}] [1 2 3 4 1 7]) -> [1 2 1]

luxbock15:05:49

ah I see, yeah makes sense