You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
add new binary (unary?) operator -ALL and -NOTALL and -ANY #7925
$a=$true,$true,$false$b=$false,$false,$false# Not one False
PS>$a-all $true$false# Not one True
PS>$b-all $false$true
PS>$a-notall $true$true
PS>$b-notall $false$false# At least one True
PS>$a-any $true$true# At least one True
PS>$b-any $true$false
another example:
if ($a-any $true-and$a-notall $true) {
"At least one True and one False"
}
maybe a short syntax like this:
if (-any $a-and-notall $a) {
"At least one True and one False"
}
-any is the -contains operator
-notany is the -contains operator
For all, just use -notcontains if its binary:
#For -Any or -All
($a -notcontains $true)
#if any are $true, it returns false, if none are $true (all $false), it returns $true
($a -notcontains $false)
#if any are $false, it returns false, if none are $false (all $true), it returns $true
-notall is also ambiguous, does it mean that at least one is and at least one is not? in which case:
($a -contains $true -and $a -contains $false)
#inherently has the notall property
For objects containing multiple values (other than true/false), you can use Group-Object, Sort-Object and a few other cmdlets. I don't see where these operators would improve things.
-any is the -contains operator
-notany is the -contains operator
For all, just use -notcontains if its binary:
#For -Any or -All
($a -notcontains $true)
#if any are $true, it returns false, if none are $true (all $false), it returns $true
($a -notcontains $false)
#if any are $false, it returns false, if none are $false (all $true), it returns $true
-notall is also ambiguous, does it mean that at least one is and at least one is not? in which case:
($a -contains $true -and $a -contains $false)
#inherently has the notall property
For objects containing multiple values (other than true/false), you can use Group-Object, Sort-Object and a few other cmdlets. I don't see where these operators would improve things.
($a -in $collection) is the same ($collection -contains $a)
in other case -all -notall and -any is easy to read and also simplified syntax
I would argue that $array -contains $item is far easier to read than $array -any $item (at least for those of us perhaps who are most accustomed to English over other languages and/or have it as our birth-tongue).
And really, the only thing you can't currently do with a single operator that you're suggesting is the -notall, which would be most neatly solved, I think with a fairly simple expression that arguably makes more semantic sense than the overly-shortened -notall operator suggested:
@($Array-eq$Item).Count -ne$Array.Count
(And, of course, Powershell-User's suggestion also has merit there, although I am unsure which is "better", at least performance-wise.)
While I do like the idea, as Powershell-User mentions, the functionality is already present, and I think the existing operators are more than sufficiently clear in intention.
$array -contains $item is far easier to read than $array -any $item
Agreed but if any accepts (or by default uses) a filter expression it becomes a tiny bit more interesting. This would be kind of like the .Where{} method e.g. (2,4,6,7).Where{$_ -le 4}. An Anymethod would accept a filter e.g. (2,4,6,7).Any{$_ % 2} which in this case, detects if there are any odd numbers in the array. Or as an operator (2,4,6,7) -any {$_ % 2}. You can do this today with LINQ:
As you state, .Where{} is perfectly capable of this.
I believe there have been discussions about whether or not to add -where and foreachoperators as well, which it appears may be more useful to you in this kind of scenario.
Was looking for interesting issues to work on last night and stumbled on this.
What Keith Hill (@rkeithhill) suggests (lambda containment operators) makes much more sense, and can easily be implemented with a few modifications to the existing -contains op implementation, like in this branch:
Bruce Payette (@BrucePay) are there any active efforts to pursue LINQ/extension methods any time soon? No need to add this if that's on the roadmap
Reacted by p0W3RH311
Reacted by Keith Hill and Rain Sallow (/u/ta11ow)
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
Activity
Powershell-User commentedon Oct 2, 2018
-any is the -contains operator
-notany is the -contains operator
For all, just use -notcontains if its binary:
-notall is also ambiguous, does it mean that at least one is and at least one is not? in which case:
For objects containing multiple values (other than true/false), you can use Group-Object, Sort-Object and a few other cmdlets. I don't see where these operators would improve things.
kvprasoon commentedon Oct 2, 2018
looks interesting !!!
p0W3RH311 commentedon Oct 3, 2018
($a -in $collection) is the same ($collection -contains $a)
in other case -all -notall and -any is easy to read and also simplified syntax
vexx32 commentedon Oct 3, 2018
I would argue that
$array -contains $itemis far easier to read than$array -any $item(at least for those of us perhaps who are most accustomed to English over other languages and/or have it as our birth-tongue).And really, the only thing you can't currently do with a single operator that you're suggesting is the
-notall, which would be most neatly solved, I think with a fairly simple expression that arguably makes more semantic sense than the overly-shortened-notalloperator suggested:(And, of course, Powershell-User's suggestion also has merit there, although I am unsure which is "better", at least performance-wise.)
While I do like the idea, as Powershell-User mentions, the functionality is already present, and I think the existing operators are more than sufficiently clear in intention.
rkeithhill commentedon Oct 3, 2018
Agreed but if
anyaccepts (or by default uses) a filter expression it becomes a tiny bit more interesting. This would be kind of like the.Where{}method e.g.(2,4,6,7).Where{$_ -le 4}. AnAnymethod would accept a filter e.g.(2,4,6,7).Any{$_ % 2}which in this case, detects if there are any odd numbers in the array. Or as an operator(2,4,6,7) -any {$_ % 2}. You can do this today with LINQ:But it's kind of a PITA.
I suppose you could do the same with
-alle.g.(2,4,6,7) -all {$_ -lt 10}would return $true.Or maybe it would be better if PowerShell just worked more easily with the various LINQ
Enumerablemethods?vexx32 commentedon Oct 3, 2018
As you state,
.Where{}is perfectly capable of this.I believe there have been discussions about whether or not to add
-whereandforeachoperators as well, which it appears may be more useful to you in this kind of scenario.BrucePay commentedon Oct 3, 2018
When we get around to supporting LINQ, these operations will be covered and it will simply be
HumanEquivalentUnit commentedon Oct 3, 2018
Where's the GoFundMe for LINQ support? ;) 👍
vexx32 commentedon Oct 4, 2018
If I knew anything about LINQ I'd be all over that, but I think it's a bit over my head for the present moment. 😄
IISResetMe commentedon Feb 16, 2019
Was looking for interesting issues to work on last night and stumbled on this.
What Keith Hill (@rkeithhill) suggests (lambda containment operators) makes much more sense, and can easily be implemented with a few modifications to the existing
-containsop implementation, like in this branch:Bruce Payette (@BrucePay) are there any active efforts to pursue LINQ/extension methods any time soon? No need to add this if that's on the roadmap
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 23, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.