Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>$args is unrolled. Remember that function parameters are normally passed using space to separate them. When you pass in 1,2,3 you are passing in a single argument that is an array of three numbers that gets assigned to $args[0]:</p> <pre><code>PS&gt; function UnrollMe { $args } PS&gt; UnrollMe 1 2 3 | measure Count : 3 </code></pre> <p>Putting the results (an array) within a grouping expression (or subexpression e.g. <code>$()</code>) makes it eligible again for unrolling so the following unrolls the object[] containing 1,2,3 returned by UnrollMe:</p> <pre><code>PS&gt; ((UnrollMe 1,2,3) | measure).Count 3 </code></pre> <p>which is equivalent to:</p> <pre><code>PS&gt; ((1,2,3) | measure).Count 3 </code></pre> <p>BTW it doesn't just apply to an array with one element.</p> <pre><code>PS&gt; ((1,2),3) | %{$_.GetType().Name} Object[] Int32 </code></pre> <p>Using an array subexpression (<code>@()</code>) on something that is already an array has no effect no matter how many times you apply it. :-) If you want to prevent unrolling use the comma operator because it will <em>always</em> create another outer array which gets unrolled. Note that in this scenario you don't really prevent unrolling, you just work around the unrolling by introducing an outer "wrapper" array that gets unrolled instead of your original array e.g.:</p> <pre><code>PS&gt; (,(1,2,3) | measure).Count 1 </code></pre> <p>Finally, when you execute this:</p> <pre><code>PS&gt; (UnrollMe a,b,c d) | %{$_.GetType().Name} Object[] String </code></pre> <p>You can see that UnrollMe returns two items (a,b,c) as an array and d as a scalar. Those two items get sent down the pipeline separately which is the resulting count is 2.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload