This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-01-31
Channels
- # babashka (23)
- # beginners (65)
- # calva (126)
- # cider (23)
- # clj-kondo (10)
- # clojure (41)
- # clojure-europe (5)
- # clojure-nl (2)
- # clojure-uk (6)
- # clojurescript (78)
- # contributions-welcome (1)
- # datomic (9)
- # events (1)
- # graalvm (2)
- # meander (10)
- # off-topic (81)
- # pathom (5)
- # shadow-cljs (3)
- # spacemacs (6)
- # vim (3)
- # xtdb (4)
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.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))