Fork me on GitHub
#meander
<
2021-01-31
>
ribelo20:01:11

How can this be simplified?

(defn test [id]
  (m/search [@cache_ id]
    [{:fns       {?k {:input (m/scan ?in)}}
      :resolvers {?id (m/scan ?k)}
      :as ?m}
     ?id]
    [?in (test ?in)]))
I tried to use cata or with, but failed.

ribelo20:01:41

I also don't know how to return a flat collection without rewrite.

ribelo20:01:05

this also unfortunately doesn't work because !in is used before it gets to cata

(m/rewrite [@cache_ id]
    [{:fns       {?k {:input [!in ...]}}
      :resolvers {?id (m/scan ?k)}
      :as        ?m}
     ?id]
    [!in ... (m/cata [?m !in]) ...]
    [_ ?k] ?k)

ribelo20:01:28

let's say i did it, but how do i make a flat sequence out of it now?

(m/rewrite [@cache_ id]
    [{:fns       {?k {:input [!in ...]}}
      :resolvers {?id (m/scan ?k)}
      :as        ?m}
     ?id]
    [(m/cata [?m !in]) ... ?id]
    [_ ?k] ?k)
;; => [[:db/id :person/name] [:db/id :person/last-name] :person/email]

Jimmy Miller20:01:34

On my phone right now so can't dive in. But did you try rewrites? That's the search version of rewrite. You can also use (m/and !x1 !x2) on the left hand side to copy a memory variable. If you can provide some test data I should have sometime to look at this later.

ribelo21:01:51

@jimmy http://ix.io/2NSV here is the link in case you get bored and have too much time 😉

Jimmy Miller22:01:54

(defn walk-inputs [cache id]
  (m/rewrite {:id id 
              :cache cache}

    {:id (m/some ?id)
     :cache {:fns       {?fn {:input [!inputs ...]}}
             :resolvers {?id (m/scan ?fn)}}}

    (m/cata [(m/cata {:id !inputs 
                      :cache ~cache}) ... ?id])

    {:id (m/some ?id)} ?id

    [(m/or [!xs ...] !xs) ...]  [!xs ...]))
Here’s one solution. Or you could do the more mind bendy one
(defn walk-inputs [cache id]
  (m/rewrite {:id id 
              :cache cache}
    (m/and
     {:id (m/some ?id)
      :cache {:fns       {?fn {:input [!inputs ...]}}
              :resolvers {?id (m/scan ?fn)}}}
     (m/let [[(m/cata (m/or [!paths ...] !paths)) ...] (m/subst [{:id !inputs :cache ~cache} ...])]))
    
    [!paths ... ?id]

    {:id (m/some ?id)} ?id))

ribelo22:01:13

i finally did something similar to the first example

ribelo22:01:46

the second example I have to write down somehow, my mind does not comprehend it 😉