Skip to content
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

more in-depth README #62

Merged
merged 5 commits into from
Dec 16, 2015
Merged

more in-depth README #62

merged 5 commits into from
Dec 16, 2015

Conversation

jarsen
Copy link
Contributor

@jarsen jarsen commented Jun 12, 2015

This is my attempt to help out with #51.

I'm not sure how great my example is... but I think it does demonstrate the core concepts well. And it was the first example I thought of.

I also tried to give a shoutout to map and flatMap, and a reference to Javi Soto's monads article (without mentioning the words Functor or Monad in the README). I'm not sure if this is a horrible idea. Seems like now that Swift 2.0 brings error handling the higher order functions are really what make results stand out as a better (IMO) solution to error handling. Since those features are one of the compelling reasons for Result I thought it might be appropriate to highlight them a little.

Anyway let me know what you think. Hopefully it's helpful.

@jarsen jarsen mentioned this pull request Jun 12, 2015
Make it fit on one line and fix the function name so it's consistent with the previous example

Swift 2.0 introduces error handling via throwing and catching `ErrorType`. `Result` accomplishes the same goal by encapsulating the result instead of hijacking control flow. The `Result` abstraction also enables powerful functionality such as `map` and `flatMap`.

Since dealing with APIs that throw is common, you can convert functions such functions into a `Result` by using the `materialize` method. [Note: due to compiler issues, `materialize` is not currently available]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also note here that the opposite function (dematerialize) is available to access the value or throw.

@jarsen
Copy link
Contributor Author

jarsen commented Jun 13, 2015

Alright. I made a couple edits based off suggestions.

I also wonder if it might be worth mentioning things like what Argo is doing (except they are using their Decoded enum instead of Result). I also have been working on Pipes which does some pretty cool stuff with Result (although I'm biased). More advanced operators like these are definitely compelling advantages of Result, but I don't know if they are appropriate for the README.

@jarsen
Copy link
Contributor Author

jarsen commented Jun 13, 2015

Also, another idea: since one of the motives behind this lib is so that you can share a common Result type between modules, maybe it would be appropriate to mention a few popular libraries that use Result, such as ReactiveCocoa?

@neilpa
Copy link
Member

neilpa commented Jun 14, 2015

maybe it would be appropriate to mention a few popular libraries that use Result, such as ReactiveCocoa?

👍

@thbaja
Copy link

thbaja commented Jul 1, 2015

Good stuff!.
The JSON example seems to me to be a very good example actually, and should be relevant to a lot of people.

I discovered this library through ReactiveCocoa 3.0 unit tests, so for me it would be even better with examples of tying in to that framework although i recognise it might seem premature, considering that it's just a development branch. But as @jarsen mentions it's great that you can share a common Result type between modules, so why not show it :)

I agree that mentioning popular libraries that uses Result is a good idea.

@jarsen
Copy link
Contributor Author

jarsen commented Jul 2, 2015

Any other popular libraries besides ReactiveCocoa we might use?

@Thomvis
Copy link
Member

Thomvis commented Jul 7, 2015

Not sure if it classifies as popular, but I wouldn't mind if BrightFutures is mentioned. (Disclaimer: I'm the primary author of BrightFutures)

I tried searching GitHub for occurrences of Result in Podfiles/Cartfiles, but did not run into any other libraries that I recognized.

@robrix
Copy link
Contributor

robrix commented Jul 8, 2015

I think BrightFutures would be good to add 👍

@robrix
Copy link
Contributor

robrix commented Oct 30, 2015

bump

@antitypical/result: Anything else we want to add or shall we merge this?


## Result vs. Throws

Swift 2.0 introduces error handling via throwing and catching `ErrorType`. `Result` accomplishes the same goal by encapsulating the result instead of hijacking control flow. The `Result` abstraction allows enables powerful functionality such as `map` and `flatMap`, making `Result` more composable than `throw`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

abstraction allows enables powerful

@neilpa
Copy link
Member

neilpa commented Oct 30, 2015

Few minor notes, but 👍 otherwise

@neilpa
Copy link
Member

neilpa commented Oct 30, 2015

Or we could merge as-is and fix in a separate PR since this is rather old


Other methods available for processing `Result` are detailed in the [API documentation](http://cocoadocs.org/docsets/Result/).

## Result vs. Throws
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth also mentioning that you can't use throws with asynchronous APIs.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it'd be helpful to have more information here and possibly an example.

@robrix
Copy link
Contributor

robrix commented Oct 31, 2015

Or we could merge as-is and fix in a separate PR since this is rather old

I’d be 👍 to that.

@nixterrimus
Copy link

I'm new to this project. I came to it through ReactiveCocoa and as I've been exploring I've been wondering where would Result make sense vs. throwing. This updated readme helped.

I have a bit of time this week, would you like me to make the changes here to help get it shipped? @robrix @jarsen @neilpa

I think that others would benefit from the information here not being locked up in a PR.

@robrix
Copy link
Contributor

robrix commented Dec 16, 2015

Let’s merge this one as-is, and then you can open a PR off master. Sound good?

@nixterrimus
Copy link

That sounds good

robrix added a commit that referenced this pull request Dec 16, 2015
@robrix robrix merged commit ccb14d6 into antitypical:master Dec 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants