Skip to content

Adding SkipIndex parameter to Select-Object - #7483

Merged
Dongbo Wang (daxian-dbw) merged 4 commits into
PowerShell:masterfrom
powercode:SkipIndex
Aug 9, 2018
Merged

Adding SkipIndex parameter to Select-Object#7483
Dongbo Wang (daxian-dbw) merged 4 commits into
PowerShell:masterfrom
powercode:SkipIndex

Conversation

@powercode

@powercode Staffan Gustafsson (powercode) commented Aug 8, 2018

Copy link
Copy Markdown
Collaborator

PR Summary

Resolves #7278.

Adds a parameter -SkipIndex to the Select-Object cmdlet. The semantics are the opposite of the -Index parameter. All items are passed thru except for the indices specified to -SkipIndex.

( 0..5 | Select-Object -SkipIndex 1,4 ) -join ','

0,2,3,5

PR Checklist

@dantraMSFT Dan Travison (dantraMSFT) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than a couple of suggestions; LGTM

}

/// <summary>
/// Used to display all objects not at specified index.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor grammar suggestion:
Used to display all objects not at the specified indices.

}
}

private int _indexOfCurrentObject;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:
To me these field names are confusing. _indexOfCurrentObject implies the object being processed but is actually the index into the array of index filters while _indexCount is the index of the object being processed.

I think it would improve readability if you consider changing these names to something like the following, or some variation:
_currentObjectIndex - the index of the object being processed.
_currentFilterIndex - the index of the active index filter.


It "Select-Object with SkipIndex should work" {
$results = "1", "2", "3" | Select-Object -SkipIndex 0, 2
$results.Count | Should -Be 1

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently we use new syntax:

$results | Should -HaveCount 1

Below too.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know. Fixing.

@iSazonov

Copy link
Copy Markdown
Collaborator

I edited the PR description to auto close the issue.
Keywords https://help.github.com/articles/closing-issues-using-keywords/

@daxian-dbw
Dongbo Wang (daxian-dbw) merged commit 618d9f3 into PowerShell:master Aug 9, 2018
@iSazonov

Copy link
Copy Markdown
Collaborator

Staffan Gustafsson (@powercode) Thanks for the enhancement!

Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Add Select-Object -SkipIndex parameter

4 participants