Fork me on GitHub
#specter
<
2017-06-07
>
frankmoyer15:06:05

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?

nathanmarz15:06:25

@frankmoyer what is the definition of my-nav?

frankmoyer15:06:12

@nathanmarz

(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.

nathanmarz15:06:00

ok, I suspect you don't want to be using defnav

nathanmarz15:06:06

what are you trying to accomplish with that?

nathanmarz15:06:20

there seems to be no relation between the select* and transform* codepaths

frankmoyer15:06:53

I was hoping not to implement transform*, as all I really need is a parameterized navigator.

nathanmarz15:06:17

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 ...)
  )

nathanmarz15:06:47

and then use it in any select or transform

nathanmarz15:06:15

the path itself isn't navigating anywhere

nathanmarz15:06:18

is that what you want?

nathanmarz15:06:21

it's just a filter

nathanmarz15:06:47

selected? stays navigated if the provided path selects at least one value

frankmoyer15:06:00

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.

frankmoyer15:06:49

I have been using selected? a lot because in a map I want to also return the key.

nathanmarz15:06:11

selected? has nothing to do with that

nathanmarz15:06:40

if you can simplify your example it will be easier to show you the best way to handle it

frankmoyer15:06:42

How would you get the full filtered value from the incoming structure?

nathanmarz16:06:07

that question is too generic to answer

nathanmarz16:06:22

try to come up with a simple representative example of your use case

frankmoyer16:06:32

will do. thanks!