Fork me on GitHub
#specter
<
2016-09-08
>
gphilipp21:09:07

Hi, I’m trying to solve using Specter the clojure brave and true example of chapter 3 (the one with the hobbit symmetrical body, search 'Pulling It All Together' on http://www.braveclojure.com/do-things/), but I can’t find a way to do it. Can anybody enlighten me ?

gphilipp21:09:16

My best shot is to transform existing parts, but I didn’t add them to the whole collection :

(transform [ALL needs-matching-part?]
           make-matching-part
           asym-hobbit-body-parts)

loganmhb22:09:01

@gphilipp one way to do that is with multi-transform, I think:

(multi-transform [ALL needs-matching-part? (multi-path (terminal identity)
                                                       (terminal make-matching-part))]
                 asym-hobbit-body-parts)

loganmhb22:09:34

dunno if there’s a way to avoid the explicit identity

aengelberg22:09:24

I don't think that would work, it would overwrite the value with the second transformation in multi-path

loganmhb22:09:45

ah, I think you’re right

loganmhb22:09:04

was testing with range and misinterpreted the output 🙂

aengelberg22:09:52

there might be a way with com.rpl.specter.zipper

loganmhb22:09:51

here’s something:

(select [ALL keyword? (continue-then-stay (transformed STAY str))] [:a :b :c])
[":a" :a ":b" :b ":c" :c]

gphilipp22:09:45

That looks ok. Not very readable though :-/

gphilipp22:09:29

Thanks anyway !

aengelberg22:09:27

(transform [VECTOR-ZIP LEFTMOST (stay-then-continue RIGHT) NODE-SEQ (view set) (collect-one FIRST) (subset #{})] (fn [body-part _] #{(make-matching-part body-part)}) asym-hobbit-body-parts)

caio22:09:00

so, I have this small path that I’m using in several places: [map? ALL (sp/if-path #(-> % first ks) LAST)] it’s basically a select-key (didn’t use (view #(select-key …)) cause it doesn’t work on transforms :(). is this the right way of doing it? if it is, how can I transform it into a nav? my goal is to call (key-selector ks) inside a path

caio22:09:59

I looked into defnav, but couldn’t understand how to do it

Chris O’Donnell22:09:19

There might be a way to do it with multi-path.

caio22:09:10

well, that was easy. thanks again @codonnell