I’ve been using arrays lately and really missing Python’s “in” operator.
e.g.:
if ("hello" in ["hello", "there", "sup"]):
print "this prints :)"
I’ve made up for it a little bit by creating a “ThereExists-Object” function, like so:
function ThereExists-Object([System.Management.Automation.ScriptBlock] $sb)
{
return ($input | where $sb) -as [bool]
}
New-Alias -Name ThereExists -Value ThereExists-Object
e.g.:
if ($arrayOfStuff | thereexists { $_ -eq "hello" } )
{
write-host "this prints too"
}
obviously I could define another function for this as well… but I’d like to know if there’s some syntactical sugar that I’m unfamiliar with that could get this job done.
So… is there any?
source: http://technet.microsoft.com/en-us/library/ee692798.aspx