-
Notifications
You must be signed in to change notification settings - Fork 67
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
Add assoc-in-some function #80
base: master
Are you sure you want to change the base?
Conversation
I'm on the fence about this. Could you give some reasons why using (update data :user assoc-some :name nil)
(assoc-in-some data [:user :name] nil)
(update-in data [:account :user] assoc-some :name nil)
(assoc-in-some data [:account :user :name] nil) Also, what are your thoughts regarding Finally, can you change the commit message to |
Actually, see: #72 (comment). I'm thinking the same reasoning applies here: (some->> v (assoc-in data [:account :name]))
(assoc-in-some data [:account :user :name] v) Given that this function would require more characters than the existing idiomatic solution, I'm inclined to close this for the same reasons as last time. |
The some->> example is missing one of the keys which is why it's shorter lol. |
@weavejester So, like #72 (comment), I was also under the impression that separating this into a new helper function makes writing clearer. When a person uses the But I don't see any problems using |
0bf4deb
to
89f85ac
Compare
I updated the commit message |
Looking at the Clojure documentation, some functions end with |
Whoops!! (some->> v (assoc-in data [:account :user :name]))
(assoc-in-some data [:account :user :name] v) So I guess it's 5 characters shorter. |
@weavejester I was seeing that this function exists in another clojure lib: clojure-lsp I think having |
Description:
This Pull Request adds the
assoc-in-some
function to the repository, complementing the existingassoc-some
function. Theassoc-in-some
function was implemented to make it possible to associate values in nested associative structures, as long as the value is not null (nil).Motivation:
The
assoc-some
function currently supports conditional binding on a single map level, allowing you to bind a value to a key only if that value is not null. However, this functionality is limited to top-level map structures and does not cover associations in nested structures such as maps within maps.The new
assoc-in-some
function aims to fill this gap by allowing conditional associations at any level of a nested associative structure, such as maps within maps, vectors within maps, etc.By providing a convenient way to perform conditional associations on nested structures, the
assoc-in-some
function simplifies code. It improves the readability of programs that deal with complex, nested data.Example of use: