Created
September 7, 2018 08:44
-
-
Save elonmallin/ed5d912a22481ab9522d816497558d1f to your computer and use it in GitHub Desktop.
Adds the conditional ternary operator from C# to Powershell (As close as we get anyway)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
Adds the conditional ternary operator. | |
Use e.g: | |
`$Color = $Settings.HasColor |?: $Settings.Color "blue"` | |
#> | |
function ConditionalTernary { | |
param ( | |
[Parameter(ValueFromPipeline=$true)]$Value, | |
[Parameter(Position=0)]$First, | |
[Parameter(Position=1)]$Second | |
) | |
if ($Value) { $First } else { $Second } | |
} | |
Set-Alias -Name "?:" -Value ConditionalTernary |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment