This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-08-22
Channels
- # aws (12)
- # babashka (24)
- # beginners (51)
- # biff (2)
- # cherry (4)
- # cider (2)
- # clj-kondo (4)
- # cljs-dev (19)
- # clojure (70)
- # clojure-australia (4)
- # clojure-europe (39)
- # clojure-nl (4)
- # clojure-norway (6)
- # clojure-spec (9)
- # clojurescript (21)
- # component (6)
- # cursive (18)
- # data-science (9)
- # datomic (18)
- # events (2)
- # expound (4)
- # fulcro (15)
- # graalvm (2)
- # graphql (5)
- # jobs (1)
- # juxt (2)
- # leiningen (8)
- # malli (4)
- # meander (21)
- # nrepl (3)
- # observability (14)
- # off-topic (49)
- # other-languages (1)
- # pathom (13)
- # pedestal (7)
- # rdf (5)
- # re-frame (10)
- # reitit (1)
- # sql (4)
- # squint (30)
- # tools-deps (1)
- # vim (11)
hello! I am drinking the meander koolaid and wondering how to do this transform?
;; input
{:a {:m {}
:n {}}
:b {:m {}
:o {}}}
;; output
[[:a :m]
[:a :n]
[:a :m :n]
[:b :m]
[:b :o]
[:b :m :o]]
only for the first level of keys
I found the cookbook and it looks like {& (m/seqable [!ks !vs] …)}
might help here
Something like this is almost right:
(m/rewrite {:a {:m {}
:n {}}
:b {:m {}
:o {}}}
[?k (m/and (m/seqable !v ...) ?v2)]
[[?k !v] ... [?k & ?v2]]
(m/and {} (m/gather [!k (m/app keys !v)]))
[(m/cata [!k !v]) ...])
The trick, I think, is using m/cata
to “recurse” with k and its set of keys, then doing 2 different things with those keys in the other patter
It’s possible it could all be done in the one top-level map pattern, but my brain started to get cloudy.
This isn’t quite right, though, as its got an extra layer of vector nesting per top-level key, and you didn’t want that
oh wow this is so close though, I really appreciate it
oh interesting, I think that’s OK here
I was able to flatten it with m/app into
:
(m/rewrite {:a {:m {}
:n {}}
:b {:m {}
:o {}}}
[?k (m/and (m/seqable !v ...) ?v2)]
[[?k !v] ... [?k & ?v2]]
(m/and {} (m/gather [!k (m/app keys !v)]))
(m/app into (m/cata [!k !v]) ...))
I don’t understand the ask. How do I know that it should be :a :m :n and not :a :n :m?
good catch, the order is not essential to the solution here
which inner map?
Does {:a {:b {} :c {} :d {} :e {}}
produce [:a :b :c]
as one of the results or just [[:a :b] [:a :c] [:a d] [:a :e] [:a :b :c :d :e]]
?
the latter