Fork me on GitHub
#specter
<
2016-08-08
>
jjunior13004:08:30

I require both com.rpl.specter & com.rpl.specter.macros namespaces in ClojureScript

jjunior13004:08:18

all symbols from com.rpl.specter work but not com.rpl.specter.macros

jjunior13004:08:23

when I try a symbol from com.rpl.specter.macros such as transform I get this error message:

Uncaught TypeError: Cannot read property 'cljs$core$IFn$_invoke$arity$1' of undefined
core.js [32556]	anonymous
core.js [19022]	anonymous
core.js [19023]	anonymous
core.js [19038]	cljs.core.PersistentVector.cljs$core$IReduce$_reduce$arity$3
core.js [7719]	cljs.core.reduce.cljs$core$IFn$_invoke$arity$3
core.js [32555]	cljs$core$group_by
views.js?zx=ibkddq5mtrqz [72]	anonymous
specter.js [975]	$rpl$specter$protocols$Navigator$transform_STAR_$arity$3
protocols.js [46]	com$rpl$specter$protocols$transform_STAR_
impl.js [2175]	com.rpl.specter.impl.structure_path_impl
impl.js [2202]	anonymous
impl.js [2371]	anonymous
core.js [16854]	anonymous
core.js [16855]	cljs.core.map.cljs$core$IFn$_invoke$arity$2
core.js [10895]	cljs.core.LazySeq.sval
core.js [11046]	cljs.core.LazySeq.cljs$core$ISeqable$_seq$arity$1
core.js [4117]	cljs$core$seq
core.js [30313]	cljs.core.dorun.cljs$core$IFn$_invoke$arity$1
core.js [30381]	cljs.core.doall.cljs$core$IFn$_invoke$arity$1
core.js [30367]	cljs$core$doall
impl.js [3239]	com.rpl.specter.impl.all_transform._
impl.js [3177]	com$rpl$specter$impl$all_transform
impl.js [3280]	$rpl$specter$protocols$Navigator$transform_STAR_$arity$3
protocols.js [46]	com$rpl$specter$protocols$transform_STAR_
impl.js [2175]	com.rpl.specter.impl.structure_path_impl
impl.js [2202]	anonymous
impl.js [2369]	com.rpl.specter.impl.combine_same_types.combiner
impl.js [284]	anonymous
impl.js [3112]	com$rpl$specter$impl$compiled_transform_STAR_
views.js?zx=ibkddq5mtrqz [54]	anonymous

jjunior13004:08:30

I have ran lein clean and lein cljsbuild once

esirola07:08:18

@borkdude: yes, I guess one can "select" with specter producing something like the maps you worked on and then use something like the code you posted to perform the aggregations

yonatanel09:08:29

I want to get a deeply nested map value from a parsed SOAP response, so the value of key :contents when the :tag value is :second or any other I choose. I used walker but I wonder if there's a more elegant way:

(select-one [(walker #(= :second (:tag %))) :content FIRST] parsed-soap)
=>
"123"
parsed-soap is
{:tag :soap:Envelope,
 :attrs {:xmlns:xsi "",
         :xmlns:xsd "",
         :xmlns:soap ""},
 :content [{:tag :soap:Body,
            :attrs nil,
            :content [{:tag :aResponse
                       :attrs {:xmlns:a ""},
                       :content [{:tag :a:aResult,
                                  :attrs nil,
                                  :content [{:tag :first
                                             :attrs {:xsi:nil "true", :xmlns ""},
                                             :content nil}
                                            {:tag :second
                                             :attrs {:xmlns ""},
                                             :content ["123"]}
                                            {:tag :third,
                                             :attrs {:xsi:nil "true", :xmlns ""},
                                             :content nil}]}]}]}]}

nathanmarz09:08:17

@jjunior130: what version and what's the exact code you're running?

nathanmarz10:08:14

@yonatanel: my only issue with that code is it relies on a strange property of clojure which is that you can do map lookups on non-map values without error

nathanmarz10:08:31

since walker will run that function on everything it finds

nathanmarz10:08:48

that also makes that particular path less performant than ideal

nathanmarz10:08:10

the alternative is to explicitly make a recursive navigator that understands the particular structure of this data

nathanmarz10:08:01

@yonatanel:

(declarepath SoapPath)
(providepath SoapPath
  (continue-then-stay
    :content
    ALL
    SoapPath
    ))

(select-one [SoapPath #(= :second (:tag %)) :content FIRST] parsed-soap)

yonatanel10:08:45

@nathanmarz: can one be compiled by running an example first? Could be nice to tell it to walk the structure and learn for next time.

nathanmarz10:08:32

you mean use walker and then have it "learn" the path that I wrote?

yonatanel10:08:51

yes, assuming it works. I don't entirely understand it yet.

nathanmarz10:08:20

it's an interesting idea but seems like it would be full of minefields

nathanmarz10:08:35

there's no way for walker to know that the data structure is recursive, for one

shader13:08:14

any chance we could get anonymous recursive navigation? so you don't have to separately declare/provide the navigator? It seems to be a very common pattern

nathanmarz14:08:00

@shader: you can open up an issue for it

jjunior13021:08:46

@nathanmarz: nvm, it's working now. After I lein clean & lein cljsbuild once yesterday, all I did between then and now was reboot my computer. Probably I didn't restart the repl I was in yesterday (I thought I did). I'm good now. Namespace com.rpl.specter.macros is working now.