Skip to content
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

What is an "update" map mentioned in the Language basics:Maps section of the docs? #4146

Closed
benbfly opened this issue Aug 3, 2023 · 3 comments · Fixed by #4153
Closed

What is an "update" map mentioned in the Language basics:Maps section of the docs? #4146

benbfly opened this issue Aug 3, 2023 · 3 comments · Fixed by #4153
Labels

Comments

@benbfly
Copy link

benbfly commented Aug 3, 2023

The Language basics:Maps section of the docs has the following Tip:

Tip!: Appending an “update” map is a safer way to modify maps in Nextflow, specifically when passing maps through channels. This way, any references to the original map elsewhere in the pipeline won’t be modified.
https://www.nextflow.io/docs/latest/script.html#maps

I understand this to mean making a deep copy of a map rather than adding a new reference (which I agree can be important). Is this what was intended? Unfortunately, I can not figure out what the document means by an "update" map. I am not a native Groovy developer, but I searched the Nextflow documentation, google, ChatGPT, and the official Groovy Maps documentation (https://groovy-lang.org/groovy-dev-kit.html).

This tip should be clarified, perhaps with a link to the documentation for "update" maps?

@bentsherman
Copy link
Member

bentsherman commented Aug 3, 2023

It's not a technical term, that's why I put it in double quotes. Just an elaboration of the preceding example in which a map is updated by adding a new map instead of in-place mutation. See #2660 for the history behind this change. I think there was also a bytesize about it recently.

@benbfly
Copy link
Author

benbfly commented Aug 3, 2023

I think I probably would have understood the meaning if the Tip had started:
"Appending an “update” map using the '+' operator as shown above is a safer way ..."

I also think you could add at the end of the tip: "This is especially useful in adding items to the 'meta' map, which is used extensively in nf-core" (since this is the map 90% of the users are going to be dealing with).

PS: I like the + operator! Somehow the solution I found online was to clone using meta.subMap(meta.keySet())

@pditommaso
Copy link
Member

I agree with Ben, the overall tip is not clear at all. I think it should say "Creating a new map instance .." or "Cloning the map object " would be more precise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants