4 ms·
Swift's nil-coalescing operator is a great solution for this. return config.github ?? config.twitter ?? default
by metalgearsolid 7y ago
Swift's nil-coalescing operator is a great solution for this.
return config.github ?? config.twitter ?? default
- degif 7y agoThe same is in JavaScript: return (twitterUrl && config.twitter) || (githubUrl && config.github) || default
- masklinn 7y agoSeems like an unnecessary mess when you could just use ternary expressions: return twitterUrl ? config.twitter : githubUrl ? config.github : default
- Y-bar 7y agoI envy you, I’d love to grok ternary expressions better but every time I just end up having to spend a long time unrolling the logic.
- lsaferite 7y agoAnd you just introduced a bug. You refactored the code and changed the logic without noticing.