Fork me on GitHub
#specter
<
2018-06-02
>
punit-naik14:06:06

Hi Guys! I was just starting out with Specter. I had a few questions. 1. Are there error-handling functions implemented inside specter? Can I get errors as to where my navigator failed? 2. Can it work with lazy seqs? Will the laziness be preserved? 3. Can we use reducers in setval?

nathanmarz14:06:42

@punit-naik there's no particular error handling done by specter

nathanmarz14:06:54

I can usually tell where I messed up a path by looking at the stack trace

punit-naik14:06:44

So when I run (transform [ALL :a] inc [{:a 1 :b 2} {:a 2 :b 1} {:b 3}]), I get a very simple Nullpointer exception which is because the nil case is not handled by the inc fn. But don't you think one should get a more detailed exception like :a key not found at index 2?

nathanmarz14:06:42

specter will never produce a lazy output

punit-naik15:06:59

I tried running (def x (lazy-seq [1 2 3 4])) (time (cons (inc (first x)) (rest x))) and (time (transform FIRST inc x)) and the running times for them were 0.08 msecs and 0.5 msecs. Is this a considerable enough difference? So is specter indeed evaluating the entire lazy list?

nathanmarz14:06:27

though using select-first can accomplish many of the same things since it terminates navigation as soon as it encounters a matching value

nathanmarz14:06:35

don't know what you mean by #3

punit-naik15:06:36

What I meant was, is there a way to perform reduce using navigators? I am thinking of using select for this. Am I correct?

punit-naik14:06:44

So when I run (transform [ALL :a] inc [{:a 1 :b 2} {:a 2 :b 1} {:b 3}]), I get a very simple Nullpointer exception which is because the nil case is not handled by the inc fn. But don't you think one should get a more detailed exception like :a key not found at index 2?

punit-naik15:06:59

I tried running (def x (lazy-seq [1 2 3 4])) (time (cons (inc (first x)) (rest x))) and (time (transform FIRST inc x)) and the running times for them were 0.08 msecs and 0.5 msecs. Is this a considerable enough difference? So is specter indeed evaluating the entire lazy list?

punit-naik15:06:36
replied to a thread:don't know what you mean by #3

What I meant was, is there a way to perform reduce using navigators? I am thinking of using select for this. Am I correct?

nathanmarz15:06:38

@punit-naik the most efficient way to reduce over navigated values is with traverse

👍 4
nathanmarz15:06:42

timing a single invocation tells you absolutely nothing, since neither specter nor the jvm have had a chance to optimize that callsite

nathanmarz15:06:01

use criterium for benchmarking

nathanmarz15:06:54

I think you want (transform [ALL (must :a)] inc [{:a 1 :b 2} {:a 2 :b 1} {:b 3}]) for that code

punit-naik15:06:58

Okay but I if I just forget to use must. The error stack-trace seems pretty unhelpful in that case no?

punit-naik15:06:58

Okay but I if I just forget to use must. The error stack-trace seems pretty unhelpful in that case no?

nathanmarz15:06:13

your path says to navigate to that key

nathanmarz15:06:34

it's doing exactly what you instructed

nathanmarz15:06:28

it's like doing (update {} :a inc)