PowerShell / PowerShell/PowerShell

Negative Array/String Multiplication (Easy Reverse)

Open
#26,073 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Issue-Enhancement Needs-Triage WG-Engine WG-NeedsReview
Dominant language
C#
Stars
55.5k
Forks
8.5k
Avg merge
1d 2h
Merged PRs (30d)
88

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
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no source files, tests, or entry points. Start by reproducing the existing positive array-multiplication examples, then trace where multiplication semantics are handled. Done means negative multiplication reverses and repeats arrays and strings as shown, including reverse iteration behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.