-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion: Consider using Result instead of optional response and error #414
Comments
Thanks for the suggestion! This overlaps with some of the proposal in #391 to encapsulate Route/Match in a response object. That refactoring is underway in #406. We’ve been going back and forth about whether the options object and error should be members of the response object or live alongside it in the completion handler. The optionality is unfortunate, given that a nontrivial response is mutually exclusive with an error. That might be a case for using an enumeration with associated values. 🤔 A generic response type would be an interesting idea. So far we’ve been thinking about a response protocol, which would enforce the presence of a few members we think would be common to any navigation-related Mapbox API. But a generic type might be a cleaner way to go about that. Please have a look at #406. We’d welcome suggestions, though we also expect these types to require additional rounds of refactoring, such as for waypoints in #388.
As things stand, the response objects would fall back to the waypoints in the options object: mapbox-directions-swift/Sources/MapboxDirections/RouteResponse.swift Lines 42 to 44 in fe77075
However, certain errors will pass no waypoints to the completion handler, while others will pass in the response object’s waypoints: mapbox-directions-swift/Sources/MapboxDirections/Directions.swift Lines 187 to 189 in fe77075
mapbox-directions-swift/Sources/MapboxDirections/Directions.swift Lines 194 to 196 in fe77075
/cc @JThramer |
Oh whoops, I didn’t realize you were referring to the Result type in the standard library – that’s a good idea. |
Yeah this is a fantastic idea, and we should implement it as a fast-follow. |
Fixed in #418. |
This is merely a suggestion. We could use Result for completion handlers instead of all optional arguments:
This still can be done before 1.0.0 release. The only thing I am not sure about is
[Waypoint]
inRouteCompletionHandler
. Is it always returned when routes are returned? Or is it possible to get waypoints but not routes or vice-versa?The text was updated successfully, but these errors were encountered: