expr icon indicating copy to clipboard operation
expr copied to clipboard

Deep nil coalescing `??`

Open antonmedv opened this issue 2 years ago • 3 comments

Right now, in order to use ?? user have to use ?. instead of . in nested structures.

events[0]?.labels?.value ?? 'defaul'

My idea is to make left hand side of ?? optional by default. So in case user written:

events[0].labels.value ?? 'defaul'

All member accesses to label/value/events will be optional. As well as array element access.

I really like this idea and think it makes much sense.

antonmedv avatar Feb 20 '24 21:02 antonmedv

Also implement opcode to do chained optional fetch

antonmedv avatar Feb 20 '24 21:02 antonmedv

@antonmedv : I have addressed these issues in the pull request. Could you please review this PR #583

ckganesan avatar Feb 22 '24 13:02 ckganesan

Cool! Will take a look!

antonmedv avatar Feb 22 '24 14:02 antonmedv