meander

All things about https://github.com/noprompt/meander Need help and no one responded? Feel free to ping @U5K8NTHEZ
2021-01-31T20:08:11.008300Z

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.

2021-01-31T20:09:41.008600Z

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

2021-01-31T20:19:05.009Z

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)

2021-01-31T20:28:28.009400Z

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 2021-01-31T20:35:34.013900Z

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.

2021-01-31T21:06:51.014600Z

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

jimmy 2021-01-31T22:22:54.014700Z

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

2021-01-31T22:32:13.014900Z

i finally did something similar to the first example

2021-01-31T22:32:46.015100Z

the second example I have to write down somehow, my mind does not comprehend it ๐Ÿ˜‰

2021-01-31T22:33:03.015300Z

thanks!