René's URL Explorer Experiment


Title: Expose the .ForEach() and .Where() methods as regular PowerShell operators · Issue #6576 · PowerShell/PowerShell · GitHub

Open Graph Title: Expose the .ForEach() and .Where() methods as regular PowerShell operators · Issue #6576 · PowerShell/PowerShell

X Title: Expose the .ForEach() and .Where() methods as regular PowerShell operators · Issue #6576 · PowerShell/PowerShell

Description: Note: This proposal arose out of the discussion in #6512 An RFC would have to be written, but I first want to see if there's a fundamental willingness to implement this. The hidden and effectively undocumented .Where() and .ForEach metho...

Open Graph Description: Note: This proposal arose out of the discussion in #6512 An RFC would have to be written, but I first want to see if there's a fundamental willingness to implement this. The hidden and effectively ...

X Description: Note: This proposal arose out of the discussion in #6512 An RFC would have to be written, but I first want to see if there's a fundamental willingness to implement this. The hidden and effectiv...

Opengraph URL: https://github.com/PowerShell/PowerShell/issues/6576

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Expose the .ForEach() and .Where() methods as regular PowerShell operators","articleBody":"Note:   \r\n* This proposal arose out of the discussion in #6512  \r\n* An RFC would have to be written, but I first want to see if there's a fundamental willingness to implement this.\r\n\r\n---\r\n\r\nThe ~~hidden~~ and effectively undocumented `.Where()` and `.ForEach` _methods_ available on every object exposed by PowerShell were introduced to support DSC in v4 and provide functionality similar to the `Where-Object` and `ForEach-Object` cmdlets, but (a) in a more performant way (albeit in an all-in-memory way)  and (b) with more features. The most comprehensive documentation that I'm aware of is [this blog post by @KirkMunro](http://www.powershellmagazine.com/2014/10/22/foreach-and-where-magic-methods/).\r\n\r\nWhile they could simple be documented (and made more discoverable), **I suggest surfacing them as bona fide PowerShell _operators_ `-foreach` and `-where`**:\r\n\r\n* No _native_ PowerShell features  that I am aware of are exposed as _methods_: instead, functionality is surfaced as _commands_ (cmdlets/functions) and _operators_.\r\n\r\n  * Methods belong to a _different realm_, to which [`Get-Help about_Methods`](https://github.com/PowerShell/PowerShell-Docs/blob/staging/reference/6/Microsoft.PowerShell.Core/About/about_Methods.md) is the portal (albeit one that, unfortunately, currently doesn't discuss syntax pitfalls and doesn't even reference [`Get-Help about_Parsing`](https://github.com/PowerShell/PowerShell-Docs/blob/staging/reference/6/Microsoft.PowerShell.Core/About/about_Parsing.md)); it's a powerful realm and definitely worth knowing about, but it is a different realm, distinct from how PowerShell itself surfaces its functionality.\r\n\r\n* The `.Where()` and `.ForEach()` methods were introduced as such for the benefit of _DSC_ - ~~of necessity, I presume, given that the DSC DSL doesn't allow use of _pipelines_~~ (see comments below).\r\n\r\n   * Despite their general availability inside PowerShell itself, they're effectively undocumented, and many people may not even be aware of their existence (since ~~tab completion doesn't help~~ (see comments below), and neither `Get-Member` nor `.psobject.Methods` find them, you simply have to _know_ of their existence).\r\n\r\n   * Even if fully documented (and, as discussed, this is currently even lacking in the _DSC_ context, and overall Kirk's blog post is still the most complete documentation), these methods make awkward tools in general PowerShell use, due to their method syntax and output data types.\r\n\r\nHence my suggestion to **surface them as _operators_ with `[object[]]` output**, which would make them discoverable interactively (`-\u003ctab>`) , and they would be documented alongside the existing operators.\r\n\r\nThey'd make **concise complements to their cmdlet counterparts**; `-foreach` would make the `foreach` _loop_ unnecessary in many situations and with its use of `$_` reduce the existing confusion between the loop and the cmdlet (see https://github.com/PowerShell/PowerShell-Docs/issues/1514 and a rejected attempt to harmonize the two, #3830):\r\n\r\n```powershell\r\n$var = 1, 2, 3 -foreach { $_ + 1 }  # wishful thinking\r\n\r\n# vs.\r\n\r\n$var = foreach ($i in 1, 2, 3) { $i + 1 }\r\n# or (slower)\r\n$var = 1, 2, 3 | ForEach-Object { $_ + 1 }\r\n\r\n#  ---\r\n\r\n$var = 1, 2, 3 -where { $_ -gt 1 } # wishful thinking\r\n\r\n# vs.\r\n# (slower)\r\n$var = 1, 2, 3 | Where-Object { $_ -gt 1 }\r\n# or\r\n$var = foreach ($i in 1, 2, 3)  { if ($i -gt 1) { $i } }\r\n\r\n```\r\n\r\nArguably, even DSC could benefit from the cleaner operator syntax; contrast the following:\r\n\r\n```powershell\r\n# Note that this example, taken from https://docs.microsoft.com/en-us/powershell/dsc/separatingenvdata\r\n# doesn't even use `()` around the script-block argument, so the use of Where() \r\n# isn't even readily recognizable as a *method* call.\r\nNode ($AllNodes.Where{$_.Role -eq \"WebServer\"}).NodeName { ...\r\n\r\n# vs.\r\n\r\nNode ($AllNodes -where {$_.Role -eq \"WebServer\"}).NodeName { ...  # wishful thinking\r\n```\r\n\r\nEnvironment data\r\n----------------\r\n\r\nWritten as of:\r\n\r\n```powershell\r\nPowerShell Core v6.0.2\r\n```\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2018-04-05T20:08:01Z","url":"https://github.com/PowerShell/PowerShell/issues/6576"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:e290b143-b52b-d955-626b-5b0a2c5b4eec
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8574:338C0B:6407EC:9143A3:6AFD8D60
html-safe-noncee5e1235c8f74c125ab9a5a6d5cc163ef8688212e5e38734fa5f616d16939ef33
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NTc0OjMzOEMwQjo2NDA3RUM6OTE0M0EzOjZBRkQ4RDYwIiwidmlzaXRvcl9pZCI6IjMyMjA1MTMyODY2MTI5NDYyNzIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmace62988b49666e33a10bf93bcd405b3b043b982e3466aaf856b2a58e52df0538c
hovercard-subject-tagissue:311751430
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/6576/issue_layout
twitter:imagehttps://opengraph.githubassets.com/df44302c886565c01930a3c0d6da1018162d19eeed98a3706228f2ec99d9acba/PowerShell/PowerShell/issues/6576
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/df44302c886565c01930a3c0d6da1018162d19eeed98a3706228f2ec99d9acba/PowerShell/PowerShell/issues/6576
og:image:altNote: This proposal arose out of the discussion in #6512 An RFC would have to be written, but I first want to see if there's a fundamental willingness to implement this. The hidden and effectively ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamemklement0
hostnamegithub.com
expected-hostnamegithub.com
Nonebc86424ef34a73b386237872800e922d149d65ba907f63d6f150a2dcb8433bea
turbo-cache-controlno-preview
go-importgithub.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git
octolytics-dimension-user_id11524380
octolytics-dimension-user_loginPowerShell
octolytics-dimension-repository_id49609581
octolytics-dimension-repository_nwoPowerShell/PowerShell
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id49609581
octolytics-dimension-repository_network_root_nwoPowerShell/PowerShell
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release927a6c5ab1c32b38830f1b9d3050c0b9e9aa92e1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/PowerShell/PowerShell/issues/6576#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FPowerShell%2FPowerShell%2Fissues%2F6576
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FPowerShell%2FPowerShell%2Fissues%2F6576
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=PowerShell%2FPowerShell
Reloadhttps://github.com/PowerShell/PowerShell/issues/6576
Reloadhttps://github.com/PowerShell/PowerShell/issues/6576
Reloadhttps://github.com/PowerShell/PowerShell/issues/6576
PowerShellhttps://github.com/PowerShell
PowerShellhttps://github.com/PowerShell/PowerShell
Codehttps://github.com/PowerShell/PowerShell
Issues1.3k (1.3k)https://github.com/PowerShell/PowerShell/issues
Pull requests366 (366)https://github.com/PowerShell/PowerShell/pulls
Discussionshttps://github.com/PowerShell/PowerShell/discussions
Actionshttps://github.com/PowerShell/PowerShell/actions
Projectshttps://github.com/PowerShell/PowerShell/projects
Security and quality3 (3)https://github.com/PowerShell/PowerShell/security
Insightshttps://github.com/PowerShell/PowerShell/insights
https://github.com/PowerShell/PowerShell
New issuehttps://github.com/login?return_to=https://github.com/PowerShell/PowerShell/issues/6576
New issuehttps://github.com/login?return_to=https://github.com/PowerShell/PowerShell/issues/6576
Expose the .ForEach() and .Where() methods as regular PowerShell operatorshttps://github.com/PowerShell/PowerShell/issues/6576#top
Issue-Enhancementthe issue is more of a feature request than a bughttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Issue-Enhancement%22
Resolution-ExternalThe issue is caused by external component(s).https://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Resolution-External%22
https://github.com/mklement0
Michael Klement (mklement0)https://github.com/mklement0
on Apr 5, 2018https://github.com/PowerShell/PowerShell/issues/6576#issue-311751430
Collection operators .Where() and .ForEach() do not unwrap single-item results #6512https://github.com/PowerShell/PowerShell/issues/6512
this blog post by @KirkMunrohttp://www.powershellmagazine.com/2014/10/22/foreach-and-where-magic-methods/
Get-Help about_Methodshttps://github.com/PowerShell/PowerShell-Docs/blob/staging/reference/6/Microsoft.PowerShell.Core/About/about_Methods.md
Get-Help about_Parsinghttps://github.com/PowerShell/PowerShell-Docs/blob/staging/reference/6/Microsoft.PowerShell.Core/About/about_Parsing.md
MicrosoftDocs/PowerShell-Docs#1514https://github.com/MicrosoftDocs/PowerShell-Docs/issues/1514
#3830https://github.com/PowerShell/PowerShell/issues/3830
https://github.com/BrucePay
Bruce Payette (BrucePay)https://github.com/BrucePay
on Apr 5, 2018https://github.com/PowerShell/PowerShell/issues/6576#issuecomment-379082445
Michael Klement (@mklement0)https://github.com/mklement0
Travis Plunk (TravisEz13)https://github.com/TravisEz13
Issue-Enhancementthe issue is more of a feature request than a bughttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Issue-Enhancement%22
on Apr 5, 2018https://github.com/PowerShell/PowerShell/issues/6576#event-1559775863
https://github.com/BrucePay
Bruce Payette (BrucePay)https://github.com/BrucePay
on Apr 5, 2018https://github.com/PowerShell/PowerShell/issues/6576#issuecomment-379096772
Michael Klement (@mklement0)https://github.com/mklement0
Kirk Munro (@KirkMunro)https://github.com/KirkMunro
#3830https://github.com/PowerShell/PowerShell/issues/3830
https://github.com/mklement0
Michael Klement (mklement0)https://github.com/mklement0
on Apr 6, 2018https://github.com/PowerShell/PowerShell/issues/6576#issuecomment-379126948
https://github.com/mklement0
Michael Klement (mklement0)https://github.com/mklement0
on Apr 6, 2018https://github.com/PowerShell/PowerShell/issues/6576#issuecomment-379128762
https://github.com/mklement0
Michael Klement (mklement0)https://github.com/mklement0
on Apr 6, 2018https://github.com/PowerShell/PowerShell/issues/6576#issuecomment-379129752
https://github.com/mklement0
Michael Klement (mklement0)https://github.com/mklement0
on Apr 6, 2018https://github.com/PowerShell/PowerShell/issues/6576#issuecomment-379130227
https://github.com/mklement0
Michael Klement (mklement0)https://github.com/mklement0
on Apr 6, 2018https://github.com/PowerShell/PowerShell/issues/6576#issuecomment-379131488
https://github.com/mklement0
Michael Klement (mklement0)https://github.com/mklement0
on Apr 6, 2018https://github.com/PowerShell/PowerShell/issues/6576#issuecomment-379133219
https://github.com/mklement0
Michael Klement (mklement0)https://github.com/mklement0
on Apr 6, 2018https://github.com/PowerShell/PowerShell/issues/6576#issuecomment-379134260
https://github.com/vexx32
Rain Sallow (/u/ta11ow) (vexx32)https://github.com/vexx32
on Apr 6, 2018https://github.com/PowerShell/PowerShell/issues/6576#issuecomment-379292425
https://github.com/mklement0
Michael Klement (mklement0)https://github.com/mklement0
on Apr 6, 2018https://github.com/PowerShell/PowerShell/issues/6576#issuecomment-379352207
Rain Sallow (/u/ta11ow) (@vexx32)https://github.com/vexx32
-split operatorhttps://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_split?view=powershell-6
https://github.com/vexx32
Rain Sallow (/u/ta11ow) (vexx32)https://github.com/vexx32
on Apr 6, 2018https://github.com/PowerShell/PowerShell/issues/6576#issuecomment-379403689
https://github.com/mklement0
Michael Klement (mklement0)https://github.com/mklement0
on Apr 6, 2018https://github.com/PowerShell/PowerShell/issues/6576#issuecomment-379405026
Rain Sallow (/u/ta11ow) (@vexx32)https://github.com/vexx32
https://github.com/mklement0
Michael Klement (mklement0)https://github.com/mklement0
on Apr 8, 2018https://github.com/PowerShell/PowerShell/issues/6576#issuecomment-379564142
Bruce Payette (@BrucePay)https://github.com/BrucePay
Document the v4+ .ForEach() and .Where() methods ("collection operators") MicrosoftDocs/PowerShell-Docs#2307https://github.com/MicrosoftDocs/PowerShell-Docs/issues/2307
Amend "about_Methods" to contrast the syntax differences with argument mode, show pitfalls MicrosoftDocs/PowerShell-Docs#2308https://github.com/MicrosoftDocs/PowerShell-Docs/issues/2308
Michael Klement (mklement0)https://github.com/mklement0
on Apr 8, 2018https://github.com/PowerShell/PowerShell/issues/6576#event-1562674468
https://github.com/mklement0
Michael Klement (mklement0)https://github.com/mklement0
on Apr 8, 2018https://github.com/PowerShell/PowerShell/issues/6576#issuecomment-379575727
Bruce Payette (@BrucePay)https://github.com/BrucePay
PowerShell/PowerShell-RFC#126https://github.com/PowerShell/PowerShell-RFC/pull/126
Michael Klement (mklement0)https://github.com/mklement0
completedhttps://github.com/PowerShell/PowerShell/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Apr 8, 2018https://github.com/PowerShell/PowerShell/issues/6576#event-1562727953
Ilya (iSazonov)https://github.com/iSazonov
Resolution-ExternalThe issue is caused by external component(s).https://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Resolution-External%22
on Apr 11, 2018https://github.com/PowerShell/PowerShell/issues/6576#event-1567764120
Joey Aiello (joeyaiello)https://github.com/joeyaiello
on Apr 1, 2019https://github.com/PowerShell/PowerShell/issues/6576#event-2244579441
Reject RFC0034 for .ForEach() and .Where() methods as regular PowerSh…https://github.com/PowerShell/PowerShell-RFC/commit/191e91a2e4c80626ea0def15fc4388f6af5c798e
191e91ahttps://github.com/PowerShell/PowerShell-RFC/commit/191e91a2e4c80626ea0def15fc4388f6af5c798e
Sign up for freehttps://github.com/signup?return_to=https://github.com/PowerShell/PowerShell/issues/6576
Sign in to commenthttps://github.com/login?return_to=https://github.com/PowerShell/PowerShell/issues/6576
Issue-Enhancementthe issue is more of a feature request than a bughttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Issue-Enhancement%22
Resolution-ExternalThe issue is caused by external component(s).https://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Resolution-External%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.