This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-06-07
Channels
- # aleph (19)
- # aws (1)
- # beginners (75)
- # boot (28)
- # cider (1)
- # cljs-dev (12)
- # cljsrn (20)
- # clojure (350)
- # clojure-argentina (1)
- # clojure-chicago (2)
- # clojure-dev (2)
- # clojure-russia (5)
- # clojure-spec (2)
- # clojure-uk (14)
- # clojure-ukraine (3)
- # clojurescript (68)
- # component (87)
- # core-async (25)
- # core-logic (13)
- # cursive (4)
- # data-science (72)
- # datascript (59)
- # datomic (15)
- # defnpodcast (7)
- # emacs (33)
- # hoplon (5)
- # immutant (73)
- # jobs (21)
- # klipse (6)
- # lumo (14)
- # off-topic (26)
- # om (23)
- # onyx (6)
- # parinfer (37)
- # protorepl (4)
- # re-frame (13)
- # ring (2)
- # rum (3)
- # spacemacs (2)
- # specter (22)
- # sql (47)
- # uncomplicate (10)
- # unrepl (79)
- # untangled (66)
- # vim (47)
- # yada (17)
I’ve really enjoyed working with specter over the past couple of days; its code concision in dealing with nested sequences is beautiful. I’ve run into an issue that has gotten me stuck.
I have a defnav my-nav
that is returning [[] [] [["a" {:x "y"}]]]
. I cannot figure out a way to remove the empty sequences from the defnav
before returning it. I’ve read through recent posts on using (setval [ALL nil?] NONE m)
, however that only works when used outside the defnav
. Also, when I place FIRST
in a path after my-nav
like (select [my-nav FIRST] m)
, it removes the empty vectors. However, when I place that FIRST
at the last part of the navigator within my-nav
, it does not remove them. Any ideas on why specter behaves this way and any way around it?
@frankmoyer what is the definition of my-nav
?
(sp/defnav previously-assigned-not-finished
[user get-time completion-time-limit]
(select* [this structure next-fn]
(next-fn
(sp/select
(sp/selected? ;; return the matching keys-value pairs from this point
[sp/LAST ;; pick the map value (now in vector form)
:assignments ;; select :assignments entry
(sp/must annotator) ;; only the ones assigned to this user
(sp/selected? ;; pass through the assignments to both next
[(sp/must :assigned) ;; get the assigned entry
;; check that the time limit has not passed
#(> completion-time-limit (- (get-time) %))])
(sp/not-selected? ;; exclude when finished
(sp/multi-path
(sp/must :complete)
(sp/must :flagged-for-review)
(sp/must :incomplete)))])
structure)))
(transform* [this structure next-fn]
(next-fn [structure annotator])))
Any other advice is appreciated; I just started working with Specter yesterday.ok, I suspect you don't want to be using defnav
what are you trying to accomplish with that?
there seems to be no relation between the select*
and transform*
codepaths
I was hoping not to implement transform*
, as all I really need is a parameterized navigator.
for your select* code, you can just accomplish that with a regular defn
:
(defn previously-assigned-not-finished-path [user get-time completion-time-limit]
(path ...)
)
and then use it in any select
or transform
the path itself isn't navigating anywhere
is that what you want?
it's just a filter
selected?
stays navigated if the provided path selects at least one value
Yes, it is. I was trying to get more advanced with defining navigators and testing them individually, chaining them together for different filters. Given it is my second day, I think I need to spend a few more cycles with Specter.
I have been using selected?
a lot because in a map I want to also return the key.
selected?
has nothing to do with that
if you can simplify your example it will be easier to show you the best way to handle it
How would you get the full filtered value from the incoming structure?
that question is too generic to answer
try to come up with a simple representative example of your use case
will do. thanks!