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.I also don't know how to return a flat collection without rewrite.
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)
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]
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.
@jimmy http://ix.io/2NSV here is the link in case you get bored and have too much time ๐
(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))
i finally did something similar to the first example
the second example I have to write down somehow, my mind does not comprehend it ๐
thanks!