This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-02-10
Channels
- # ai (2)
- # beginners (3)
- # boot (113)
- # bristol-clojurians (2)
- # cider (77)
- # clara (43)
- # cljs-dev (48)
- # cljsrn (9)
- # clojure (319)
- # clojure-austin (2)
- # clojure-czech (4)
- # clojure-denmark (4)
- # clojure-france (4)
- # clojure-italy (4)
- # clojure-russia (2)
- # clojure-serbia (10)
- # clojure-spec (79)
- # clojure-uk (64)
- # clojurescript (109)
- # clr (3)
- # conf-proposals (21)
- # core-async (19)
- # cursive (26)
- # datascript (11)
- # datomic (19)
- # devcards (1)
- # emacs (25)
- # figwheel (9)
- # hoplon (31)
- # jobs (7)
- # jobs-discuss (14)
- # leiningen (10)
- # lumo (11)
- # off-topic (37)
- # om (40)
- # onyx (4)
- # perun (8)
- # planck (3)
- # rdf (4)
- # re-frame (40)
- # ring (11)
- # ring-swagger (2)
- # rum (21)
- # spacemacs (2)
- # specter (50)
- # untangled (93)
- # yada (13)
Hi all! I'm trying to get better at Specter. I'm doing a lot of parsing HAR files for metadata. I'm able to do what I want, but it feels...inefficient. like this:
(select [ALL #(or
(re-find #"css" (get-in % [:response :content :mimeType]))
(and (re-find #"html" (get-in % [:response :content :mimeType]))
(re-find #"tff|woff" (get-in % [:request :url]))
)
(re-find #"font" (get-in % [:response :content :mimeType]))
(and (re-find #"javascript" (get-in % [:response :content :mimeType]))
(re-find #"js" (get-in % [:request :url]))
)
(and (re-find #"image" (get-in % [:response :content :mimeType]))
(re-find #"jpg|png|gif|bmp|ico" (get-in % [:request :url]))
)
)
[:request :url]] f)
@bradford I think this is cleaner and it should be much more efficient as well:
(defn ^:direct-nav my-matcher [exp1 exp2]
(collected? [part1 part2]
(and (or (not exp1)
(re-find exp1 part1))
(or (not exp2)
(re-find exp2 part2)))
))
(select [ALL
(selected?
(collect-one :response :content :mimeType)
(collect-one :request :url)
(multi-path
(my-matcher #"css" nil)
(my-matcher #"font" nil)
(my-matcher #"html" #"tff|woff")
(my-matcher #"javascript" #"js")
(my-matcher #"image" #"jpg|png|gif|bmp|ico")
))
:request
:url]
f)
minor optimization, not necessary
explained in https://github.com/nathanmarz/specter/wiki/Specter's-inline-caching-implementation
Is it idiomatic to use collect-one
in that way if you're trying to, uh, introduce a variable that will be used by a downstream navigator?
yea collect-one
+ collected?
should do what you need
you can use DISPENSE
to drop collected values later in path (so they don't reach your transform-fn, for instance)
you can also use defrichnav
to do more custom manipulation of collected values
look at definition of DISPENSE
for an example
@nathanmarz oh... very cool. very.
@zane they're a vector
new collected values are conj'd to the end
I'm sure there's room for all sorts of new navigators to help with those sorts of issues
something like (with-fresh-collected (cond-path ...))
should be easy to do using richnav
and defdynamicnav
I opened an issue for it since it's actually a pretty good idea https://github.com/nathanmarz/specter/issues/175
I have a feeling the use cases for that would be better served by with-fresh-collected
not sure, this part of the design space is fairly unexplored
would need to see more use cases
yea, that and next-fn
expects to be passed in the new vals + the next value to navigate to
defnav
is a thin wrapper around defrichnav
@zane oh yea, you'll need late-bound-richnav