This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-06-02
Channels
- # bangalore-clj (1)
- # beginners (5)
- # cider (24)
- # clara (2)
- # cljs-dev (6)
- # cljsrn (2)
- # clojure (10)
- # clojure-austin (2)
- # clojure-serbia (1)
- # clojure-spec (6)
- # clojure-uk (6)
- # clojurescript (59)
- # cursive (1)
- # datomic (10)
- # emacs (3)
- # events (7)
- # graphql (1)
- # jobs (2)
- # lein-figwheel (9)
- # off-topic (40)
- # pedestal (5)
- # portkey (2)
- # re-frame (5)
- # reagent (20)
- # shadow-cljs (7)
- # spacemacs (4)
- # specter (19)
- # testing (21)
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
?
@punit-naik there's no particular error handling done by specter
I can usually tell where I messed up a path by looking at the stack trace
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
?
specter will never produce a lazy output
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?
though using select-first
can accomplish many of the same things since it terminates navigation as soon as it encounters a matching value
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?
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
?
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?
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-naik the most efficient way to reduce over navigated values is with traverse
timing a single invocation tells you absolutely nothing, since neither specter nor the jvm have had a chance to optimize that callsite
use criterium for benchmarking
I think you want (transform [ALL (must :a)] inc [{:a 1 :b 2} {:a 2 :b 1} {:b 3}])
for that code
Okay but I if I just forget to use must
. The error stack-trace seems pretty unhelpful in that case no?
Okay but I if I just forget to use must
. The error stack-trace seems pretty unhelpful in that case no?
your path says to navigate to that key
it's doing exactly what you instructed
it's like doing (update {} :a inc)
okay.