Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Neither Square not Wrap will do what you're trying in #'s 5 and 7. Regardless of whether you put an array within a grouping expression () as you do in Square or you use the comma operator as you do in Wrap, when you use these functions in the pipeline their output is unrolled as it is feed to the next pipeline stage one at a time. Similarly in 6 and 8, it doesn't matter that you pipe in multiple objects, both Square and Wrap will feed them out one at a time to your foreach stage.</p> <p>Cases 9 and 10 seem to indicate a bug in PowerShell. Take this modified snippet and try it:</p> <pre><code>"a" | SquareAndWrap | % { # 9. only @() and $() succeed $_.GetType().FullName $_.Length $lhs -f [object[]]$_ $lhs -f [object[]]($_) $lhs -f @($_) $lhs -f $($_) } </code></pre> <p>It works. It also shows that the foreach alreadyd receives an object[] size 2 so <code>$_</code> should work without casting to [object[]] or wrapping in a subexpression or array subexpression. We have seen some V2 bugs related to psobjects not unwrapping correctly and this appears to be another instance of that. If you unwrap the psobject manually it works e.g. <code>$_.psobject.baseobject</code>.</p> <p>I "think" what you are shooting for in Wrap is this:</p> <pre><code>function Wrap2 { Begin {$coll = @();} Process {$coll += $_} End {,$coll} } </code></pre> <p>This will accumulate all pipeline input and then output it as a single array. This will work for case 8 but you still need to cast to [object[]] on the first two uses of the <code>-f</code> operator.</p> <p>BTW the parens in both Square and Wrap and the outer parens in SquareAndWrap are unnecessary. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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