An example in the manual about conditions within comprehensions would be great

I am not sure if this is the right place to mention this and if it works this way, but I am going to give it a try. I earlier read a post asking for improvements on the manual, and in that spirit this is meant with best intentions to make life easier for others.

In the manual section Comprehensions, it would be really nice to mention the possibility to use conditional such as in:

julia> [x^2 for x in 1:4 if iseven(x)]
[4,16]

This functionality is simple enough that it basically does not require any more explanation and it should not confuse anyone, but at least I did not anticipate this exact way to do so or even its existence without reading about it.

In particular, it is nice to know that this works with tuple(...) as well, which is something one might expect upon reading the example above.

1 Like

It’s actually there:

Generated values can be filtered using the if keyword:

julia> [(i,j) for i=1:3 for j=1:i if i+j == 4]
2-element Vector{Tuple{Int64, Int64}}:
 (2, 2)
 (3, 1)

Or, on the top of each page there is a link “Edit on GitHub”. Just try it it’s easy enough.

2 Likes

Oh, I did not see it down there, though I have to say that I would personally prefer it to come up much earlier.

I honestly assumed the “Edit on GitHub” option would just demand of me to have some specific rights. Thanks for mentioning it, maybe I will give it a try with what I mentioned.

So I guess when the section is edited, then someone may review it and possibly approve to merge it into existence in the actual manual?

1 Like

Yep! There’s a video describing this here:

(I think that is talking about a package but it’s actually very similar for Julia itself).

1 Like

Yes - by clicking that button, editing & saving, a new PR is created, which is then reviewed by maintainers and (if good to go) merged into the main repo. When the docs are then built for the next version, they’ll be updated with your change.

1 Like