Assume we have:
$a = @(1, @(2, @(3)))
I would like to flatten $a to get @(1, 2, 3).
I have found one solution:
@($a | % {$_}).count
But maybe there is a more elegant way?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Piping is the correct way to flatten nested structures, so I’m not sure what would be more ‘elegant’. Yes, the syntax is a bit line-noisy looking, but frankly quite serviceable.
2020 Edit
The recommended syntax these days is to expand
%toForEach-Object. A bit more verbose but definitely more readable: