4 ms·
I do use patterns like this (Swift code): switch (githubURL, twitterURL) { case (let .some(url), _): return config.github // I prefer GitHub and ignore T
by dep_b 7y ago
I do use patterns like this (Swift code):
switch (githubURL, twitterURL) {
case (let .some(url), _): return config.github // I prefer GitHub and ignore Twitter
case (.none, let .some(url)): return config.twitter // Otherwise I'll see if I have Twitter
case (.none, .none): return {} // If I have neither I'll create something new
}
But the code looks like JS and I think it doesn't support switching on tuples?
Bonus in Swift is that the compiler actually deduces that I handled all possible cases. No surprises here. Much better than if/then
- bobbylarrybobby 7y agoThis would probably get messy if you had a large number of URLs to check, and also would be very hard to modify. A bunch of `if` statements that return early would be a lot easier to work with.
- dep_b 7y agoAnd a bunch of `if` statements could get hard to maintain once it turns into a bunch of related compound statements, while it doesn't check for missing combinations compile-time. But I don't think you should call any function outside of constructors with more than three-ish parameters to begin with, so probably you would get a dictionary or list of URL's by the time it grows out of control.