-
-
Notifications
You must be signed in to change notification settings - Fork 823
Invoke-NullCoalescing lies #93
Copy link
Copy link
Closed
Milestone
Description
I'm not sure why this command is exported publicly? It has nothing to do with Git, and as such I'd prefer it to not be exported, honestly. If you are going to export it, though, it should do what the name says it does.
PS> Invoke-NullCoalescing '' 'oops'
oops
PS> Invoke-NullCoalescing $false 'oops'
oops
PS> Invoke-NullCoalescing 0 'oops'
oops
I'm sure you can think of many other ways to get the wrong result here. However, there is one more example that you may consider correct, but I find to be very confusing.
PS> Invoke-NullCoalescing { } 'oops'
oops
Invoking the ScriptBlocks may be what you need, but it seems very surprising to me. If I were to implement this it would have been simply:
function Invoke-NullCoalescing {
$args | Where-Object { $_ -ne $null } | Select-Object -First 1
}To include the script block processing, something like:
function Invoke-NullCoalescing([switch]$ProcessScriptBlocks) {
$args | ForEach-Object {
if ($_ -is [ScriptBlock] -and $ProcessScriptBlocks) {
& $_
} else {
$_
}
} | Where-Object { $_ -ne $null } | Select-Object -First 1
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels