|
strange PowerShell pipe semantics Hello --
Can anyone explain why PowerShell has these semantics:
---8<---
function Write-Type ($o) {
if ( $o -eq $null ) {
Write-Host "Null"
} else {
Write-Host $o.GetType().Name
}
}
$list = @()
Write-Type $list # Object[]
$result = $list | %{ $_ }
Write-Type $result # Null
$list = @(1)
Write-Type $list # Object[]
$result = $list | %{ $_ }
Write-Type $result # Int32
$list = @(1,2)
Write-Type $list # Object[]
$result = $list | %{ $_ }
Write-Type $result # Object[]
--->8---
....I would argue that an operation on a list should result in a list --
unless it's specifically a conversion operation. I know how to force
PowerShell to return a list but the semantics of the above seem strange,
why would PowerShell return different types based on the contents of the
list?
Thanks,
-- Jason |