I have the following simplified code:
# My "original" Null-coalescing operator
function or { $args[0] ? $args[0] : $args[1] }
function c1 { "code $($args ? $args : './')" }
function c2 { "code $($args ?? './')" }
function c3 { "code $(or $args './')" }
The output looks like this:
Case 1:
❯ c1
code './'
❯ c2
code
❯ c3
code './'
Case 2:
❯ c1 .gitconfig
code .gitconfig
❯ c2 .gitconfig
code .gitconfig
❯ c3 .gitconfig
code .gitconfig
I just don’t understand why the ??
operator doesn’t work as I would expect it in the c2
Output of Case 1
. It sadly ruins my potential use-cases for the operator for me.
Can someone explain why this is the case?