Of course you can put arbitrary functions in either, so in general this operator will be useful – but when both code paths differ only in data you can reduce to a nil-coalescing though. E.g. the initial example can be written as ;-)
Ultimately, it's a matter of taste.
The ?? | operator, however, allows me express the same idea in the style of an operator (ternary conditional) that's already common in many programming languages.
Of course you can put arbitrary functions in either, so in general this operator will be useful – but when both code paths differ only in data you can reduce to a nil-coalescing though. E.g. the initial example can be written as ;-)
Just in an attempt at playing code golf, the int example could also be written as
Though, of course again it's specific to the second code path happening to be convenient – in general the operator will remain more useful.
One could write
But I think that fails in the direction of
So your solution wins here ;-)
Ultimately, it's a matter of taste.
The
?? |
operator, however, allows me express the same idea in the style of an operator (ternary conditional) that's already common in many programming languages.Using map in this way is documented for this use in the standard library, so I prefer that method.