-
Notifications
You must be signed in to change notification settings - Fork 8k
Description
Summary of the new feature / enhancement
As a PowerShell user and developer, I often want to reverse an array or string.
As a developer who has been using array multiplication to pretty great effect in Turtle, I think it would be extraordinarily geometrically interesting to be able to reverse and repeat a range of steps in a single statement.
It would also provide a shorter way to reverse a list within a single expression (currently, one has to declare the array and then call [Array]::Reverse, which returns nothing). This benefit of simplicity would also extend to strings.
Proposed technical implementation details (optional)
PowerShell already supports array multiplication of a positive number. It should be fairly trivial to support array multiplication of a negative number as well: simply create a reversed copy and then duplicate that array.
Proposed syntax:
1,2,3 * 2 # will produce 1,2,3,1,2,3
1,2,3 * -2 # should produce 3,2,1,3,2,1
This would also open up easy "reverse iteration", without ranges
# Get a list of files in the current folder in reverse order
foreach ($file in @(Get-ChildItem -Path . -File) * -1) {
$file
}