<p dir="auto">It would be convenient in many cases to be able to add a filtering condition to comprehensions, something like:<br>
[ f(x) for x in 1:n if somecondition(x)]</p>
<p dir="auto">where the resulting array only contains those x where somecondition(x) == true. This mirrors python's syntax.</p>
<p dir="auto">Quoting <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/rtzui/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/rtzui">@rtzui</a> in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="3572324" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/547" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/547/hovercard" href="https://github.com/JuliaLang/julia/issues/547">#547</a>:<br>
On the other hand more powerful:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="x=[1,2,3,4,510,1,2,3,1,9]
y=[sqrt(a) | a ∈ x, x%2==0]"><pre class="notranslate"><code class="notranslate">x=[1,2,3,4,510,1,2,3,1,9]
y=[sqrt(a) | a ∈ x, x%2==0]
</code></pre></div>
<p dir="auto">(Discussion from <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/pao/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/pao">@pao</a>)<br>
There is an open syntactic question. The Haskell syntax (shown above) has guards as boolean expressions separated by commas and interspersed with membership assertions, which works as long as you can tell the difference between an expression evaluating to a boolean and a loop assignment statement. Python uses the keyword "if" to precede each guard. I'm sure there are other approaches as well.</p>
<p dir="auto">(From <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/JeffBezanson/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/JeffBezanson">@JeffBezanson</a>)<br>
It's maybe not ideal, but you can accomplish this as:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="x=[1,2,3,4,510,1,2,3,1,9]
y=[sqrt(a) | a in x[x%2==0] ]"><pre class="notranslate"><code class="notranslate">x=[1,2,3,4,510,1,2,3,1,9]
y=[sqrt(a) | a in x[x%2==0] ]
</code></pre></div>