Fork me on GitHub
#specter
<
2016-06-24
>
conaw02:06:56

If want to use specter to replace the nth value in deeply nested array, is there a better way to navigate to that value than using (srange x (inc x))

conaw03:06:18

Ideally I’d like to be able to transform the value there, or put in default if it doesn’t exist

Chris O’Donnell03:06:20

I don't know of a better way to do it, personally

Chris O’Donnell03:06:04

under the hood it does basically what you said

Chris O’Donnell03:06:32

if you want default element behavior, you could modify it to do that

aengelberg03:06:03

@conaw by array do you mean vector? if so, I believe (keypath 3) works

conaw03:06:39

yeah, I’m actually working with a matrix, so words slipped

conaw03:06:09

thanks a bunch

conaw03:06:42

So I can reasonably do a (if-path (keypath 4) LAST) right?

conaw03:06:40

or I would do (if-path (keypath 4) (keypath 4) LAST)

conaw03:06:33

or rather END

conaw03:06:14

nvm (if-path (must 3) (keypath 3) END)

conaw04:06:17

ok, here’s a question, it seems that I can substitute a value into a vector using setval , but if I want to use sp/END i have to have it wrapped in a seqable, so couldn’t insert it in in a flat way, is there a way I might get around that

(setval [(sp/if-path (sp/must 3) (sp/keypath 3) sp/END)] :newd  [:a :b :c :dd])

=>  [:a :b :c :newd]

conaw04:06:50

(setval [(sp/if-path (sp/must 3) (sp/keypath 3) sp/END)] [:newd]  [:a :b :c])
=> [:a :b :c :newd]

conaw04:06:02

basically, in assoc, if I assoc to the size of a vector, I conj onto the end, I’m looking for a similar behavior here

nathanmarz04:06:16

@conaw: I think you can do [END (keypath 0)]

luxbock07:06:35

@codonnell: sorry for disappearing last night, I ran the benchmark with (sequence (comp ...) %) substituted for (->> % ...) and it actually came out faster, 97ms vs 110 ms

luxbock07:06:55

that's really surprising to me

aengelberg17:06:06

Does (comp ...) take some time to initially build up the transducer?

nathanmarz18:06:44

@aengelberg: yes, most noticeable when operating on relatively little data

nathanmarz18:06:02

@aengelberg: the benchmarks I pasted before show a large performance difference between "precompiling" the transducer and doing it inline