8000 Utility to update entry properties: update-entry-properties by frenchy64 · Pull Request #1037 · metosin/malli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Utility to update entry properties: update-entry-properties #1037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2024

Conversation

frenchy64
Copy link
Collaborator
@frenchy64 frenchy64 commented Apr 10, 2024

This is what I came up with to answer this slack question: https://clojurians.slack.com/archives/CLDK6MFMK/p1712696483105789

@frenchy64 frenchy64 force-pushed the update-map-entry-property branch from 38112b3 to ec0d5ce Compare April 10, 2024 17:33
@frenchy64 frenchy64 marked this pull request as ready for review April 10, 2024 17:35
Copy link
Member
@ikitommi ikitommi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the implementation can be simplified a bit

(let [schema (m/schema ?schema)
e (or (find schema k)
(m/-fail! ::no-entry {:schema schema :k k}))
[k p v] (case (count e)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

entry contains always 3 elements I believe.

@@ -990,3 +990,25 @@
(mu/assoc-in [:foo :bar] :int)
(mu/assoc-in [:foo :baz] :int)
(mu/closed-schema)))))

(deftest update-entry-properties-test
(is (= [:map [:me {:a 1, :b 1} :int]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a failing test here too.

@ikitommi
Copy link
Member

well, I can do those. merging. thanks!

@ikitommi ikitommi merged commit f3ebd27 into metosin:master Apr 14, 2024
@ikitommi
Copy link
Member

48544d5?w=1

@ikitommi
Copy link
Member
(mu/find [:map [:x :int]] :x) 
; => [:x nil :int]

@frenchy64
Copy link
Collaborator Author

Thanks! I was trying to reverse engineer this line, tbh I still don't understand it.

(fn [e] (when (= (nth e 0) (nth key 1)) e))

@ikitommi
Copy link
Member

mu/find wraps the search key into a vector of [::m/find key], m/-get-entries unwraps it and returns the full entry instead of just the value behind the key. Entries are still always of size 3.

(m/-get-entries (m/schema [:map [:x :int]]) :x nil)
; => :int

(m/-get-entries (m/schema [:map [:x :int]]) [::m/find :x] nil)
; => [:x nil :int]

@ikitommi ikitommi mentioned this pull request Apr 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0