Why can't I return an empty array from a function?

I don’t see any sample code, so I’m speaking in generalities.

I force output (from a function or inline code) to arrays all the time in multiple languages. This can simplify code by handling zero to numerous objects with one set of instructions that loops thru the array. If the array is empty, the code doesn’t fail but - if required - handles .count = 0. It also handles one item as easily as 100,000.

I’m sure there are purists who will argue with this approach using some vague edge-case reasoning, but this technique has simplified my code for decades. The key here is to control the output and account for all possible cases when you process it.

/r/PowerShell Thread