Coalesce

Coalesce filter and alias
Language:
PowerShell
Keywords:
Code Snippet

### Add alias for coalesce operation ###
set-alias ?? Invoke-Coalesce -Option AllScope
filter Invoke-Coalesce ([scriptblock]$value1, [scriptblock]$value2)
{
    $v1 = &$value1
    if ($v1 -ne $null) { $v1 } else { &$value2 }
}

Example

$x = ?? { $null } { 2 }


Created 2013-07-16
comments powered by Disqus
Login