This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-02-28
Channels
- # announcements (30)
- # architecture (9)
- # aws (2)
- # babashka (23)
- # beginners (55)
- # cider (22)
- # clj-kondo (40)
- # clojure (47)
- # clojure-europe (4)
- # clojure-france (2)
- # clojure-italy (17)
- # clojure-nl (16)
- # clojure-norway (1)
- # clojure-sanfrancisco (1)
- # clojure-seattle (1)
- # clojure-spec (12)
- # clojure-uk (34)
- # clojured (3)
- # clojurescript (15)
- # core-async (11)
- # cursive (19)
- # data-science (3)
- # emacs (7)
- # events (4)
- # figwheel-main (10)
- # fulcro (33)
- # graalvm (49)
- # graphql (11)
- # instaparse (1)
- # java (7)
- # kaocha (1)
- # leiningen (7)
- # malli (3)
- # meander (69)
- # pathom (9)
- # re-frame (4)
- # rum (2)
- # shadow-cljs (34)
- # spacemacs (9)
- # sql (29)
- # tree-sitter (1)
- # yada (3)
(m/rewrite (range 100)
(!a !b ...)
{& [[!a !b] ...]})
;; => {0 1, 2 3, 4 5, 6 7, 8 9, 10 11, 12 13, 14 15}
!!!(let [t (transient {})]
(doseq [a (range 100)]
(conj! t [a a]))
(persistent! t))
;; => {0 0, 1 1, 2 2, 3 3, 4 4, 5 5, 6 6, 7 7}
I still don’t know what the hell the Clojure page on transients means by “Don’t bash in place” :man-shrugging:
So if I find bugs with epsilon
(which I’m using to build zeta
) I can patch them as I come up. Lately, I’m relying more on others to help catch/fix bugs. 🙂
@qythium The new version should be up any moment now.
[meander/epsilon 0.0.397]
Fantastic stuff! Thanks much. 👍The things I’m most exited for are bit/byte/string matching, aggregation, and data generation.
I'm not sure if your changes to rp+ etc. are technically correct - still looks like in-place modification
Hmm…
(t/is (= (r/rewrite (range 20)
(!a !b ...)
{& [[!a !b] ..20]})
{nil nil, 0 1, 4 5, 6 7, 12 13, 2 3, 14 15, 16 17, 10 11, 18 19, 8 9}))
is passing. If you’re concerned though and have doubts about the implementation, I’d be happy to merge another patch.I don't know if there is a counterexample for those cases, it might just happen to be working due to "undefined behavior"
I do need to hop off here for a bit and can bang on it when I’m back which should be in a hour or so. If you wanna hack on it thats cool too. 👍
Hi everyone! I’m trying to reshape a map with lists in it using meander, but haven’t found a way. Can this be done using only meander constructions?
(def data
{:first-name "Jimi"
:last-name "Hendrix"
:guitars
[{:brand "Fender"
:model "Stratocaster"
:year 1963}
{:brand "Fender"
:model "Stratocaster"
:year 1965}
{:brand "Gibson"
:model "Les Paul Custom"
:year 1955}]})
(m/search
data
{:first-name ?first-name
:last-name ?last-name
:guitars (m/scan {:brand ?brand})}
{:firstname ?first-name
:surname ?last-name
:make ?brand})
;; Result
({:firstname "Jimi", :make "Fender", :surname "Hendrix"}
{:firstname "Jimi", :make "Fender", :surname "Hendrix"}
{:firstname "Jimi", :make "Gibson", :surname "Hendrix"})
;; Result I would like to have. But how?
{:firstname "Jimi"
:surname "Hendrix"
:guitars
[{:make "Fender"}
{:make "Fender"}
{:make "Gibson"}]}
You can use rewrite to do this.
(m/rewrite
data
{:first-name ?first-name
:last-name ?last-name
:guitars [{:brand !brands} ...]}
{:firstname ?first-name
:surname ?last-name
:guitars [{:make !brands} ...]})
Search is going to give you back multiple possible results. If you just want one result match/rewrite is the thing you are looking for.
I think the only difference between what I posted and deleted was the use of m/gather
to grab the brands.
This is what I love about this though… converging on an otherwise identical solution quickly instead of figuring out what functional programming combo is better than another. 😂
A followup question, can the gathering be done in several “levels”?
;;;
;;; Map with lists with maps with lists.
;;;
(def data
{:first-name "Jimi"
:last-name "Hendrix"
:guitars
[{:brand "Fender"
:model "Stratocaster"
:details [{:year 1963 :origin "USA"}
{:year 1965 :origin "Mexico"}]}
{:brand "Gibson"
:model "Les Paul Custom"
:details [{:year 1955 :origin "USA"}]}]})
(m/rewrite
data
{:first-name ?first-name
:last-name ?last-name
:guitars [{:brand !brands
:model !models
:details
[{:year !years
:origin !origin}
...]}
...]}
{:firstname ?first-name
:surname ?last-name
:guitars [{:make !brands
:model !models
:manifactured
[{:year !years
:country !origin}
...]}
...]})
;; What I get
{:firstname "Jimi",
:surname "Hendrix"
:guitars [{:make "Fender",
:model "Stratocaster"}],
:manifactured [{:country "USA", :year 1963}
{:country "Mexico", :year 1965}
{:country "USA", :year 1955}],}
;; What I'm aiming for
{:firstname "Jimi"
:surname "Hendrix"
:guitars
[{:make "Fender"
:model "Stratocaster"
:manifactured [{:year 1963 :country "USA"}
{:year 1965 :country "Mexico"}]}
{:brand "Gibson"
:model "Les Paul Custom"
:manifactured [{:year 1955 :origin "USA"}]}]}
I managed to solve it using (m/app). Is this the best/ideomatic way or is there a smarter/cleaner way?
(def data
{:first-name "Jimi"
:last-name "Hendrix"
:guitars
[{:brand "Fender"
:model "Stratocaster"
:details [{:year 1963 :origin "USA"}
{:year 1965 :origin "Mexico"}]}
{:brand "Gibson"
:model "Les Paul Custom"
:details [{:year 1955 :origin "USA"}]}]})
(defn rewrite-guitar-details [guitar-details]
(m/rewrite
guitar-details
{:year ?year
:origin ?origin}
{:year ?year
:country ?origin}))
(defn rewrite-guitar [guitar]
(m/rewrite
guitar
{:brand ?brand
:model ?model
:details [!details ...]}
{:brand ?brand
:model ?model
:details [(m/app rewrite-guitar-details !details) ...]}))
(m/rewrite
data
{:first-name ?first-name
:last-name ?last-name
:guitars [!guitars ...]}
{:firstname ?first-name
:surname ?last-name
:guitars [(m/app rewrite-guitar !guitars) ...]})
(m/rewrite
data
{:first-name ?first-name
:last-name ?last-name
:guitars [{:brand !brands
:model !models
:details
[{:year !years
:origin !origin}
..!n]}
..!m]}
{:firstname ?first-name
:surname ?last-name
:guitars [{:make !brands
:model !models
:manifactured
[{:year !years
:country !origin}
..!n]}
..!m]})
By default ...
in substitution is going to put out all values. You can control how many it does by using ..!n
or ..?n
.
https://cljdoc.org/d/meander/epsilon/0.0.397/doc/operator-overview#repeating-with-varxiables(also you have a typo with manifactured)
Great, will try that! Thanks again @jimmy!
And it works!