-
Notifications
You must be signed in to change notification settings - Fork 227
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
Add tryMap. Like flatMap but for Swift2 error handling. #114
Conversation
/// This is a synonym for `tryMap`. | ||
public func >>- <T, U, Error> (result: Result<T, Error>, @noescape transform: T throws -> U) -> Result<U, Error> { | ||
return result.tryMap(transform) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not keen on overloading >>-
to mean two different things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, this should be limited to flatMap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t know of an operator that has the appropriate semantics, and I’d rather not invent one. A method without an operator is totally acceptable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A method without an operator is totally acceptable.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I'd like to see >>-
removed and not expose any operators.
Thanks for the PR! |
do { | ||
return .Success(try transform(value)) | ||
} | ||
catch { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency I'd say that catch
should be on the same line as the closing brace of do
.
Maybe it’d be better to change @antitypical/result: Any thoughts? |
Closing this and opened #118 instead. |
The tryMap function allows code that throws to be more easily wrapped.