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

RR Fetch Syntax #33

Merged
7 commits merged into from
May 21, 2016
Merged

RR Fetch Syntax #33

7 commits merged into from
May 21, 2016

Conversation

raulraja
Copy link
Contributor

@raulraja raulraja commented May 20, 2016

The following PR provides implicit syntax to lift any A to Fetch[A] as well as syntax for the most useful combinators on a Fetch[A].

@dialelo @rafaparadela Can you please review? Thanks!

Pseudo extract from the included docs contribution:

Syntax

Implicit syntax

Fetch provides implicit syntax to lift any value to the context of a Fetch in addition to the most common used combinators active within Fetch instances.

pure

Plain values can be lifted to the Fetch monad with value.fetch:

val fetchPure: Fetch[Int] = 42.fetch

Executing a pure fetch doesn't query any data source, as expected.

val result: Int = fetchPure.runA[Eval].value

error

Errors can also be lifted to the Fetch monad via exception.fetch. Note that interpreting
an errorful fetch to Eval will throw the exception so we won't do that:

val fetchFail: Fetch[Int] = (new Exception("Something went terribly wrong")).fetch[Int]

join

We can compose two independent fetches with fetch1.join(fetch2).

val fetchJoined: Fetch[(Post, User)] = getPost(1).join(getUser(2))

If the fetches are to the same data source they will be batched; if they aren't, they will be evaluated at the same time.

val result: (Post, User) = fetchJoined.runA[Eval].value

runA

Run directly any fetch to a target any target Monad with a MonadError instance in scope fetch1.runA[Eval].

val post: Eval[Post] = getPost(1).runA[Eval]

runE

Extract a fetch an get it's runtime environment fetch1.runE[Eval].

val env: Eval[FetchEnv] = getPost(1).runE[Eval]

runF

Run a fetch obtaining the environment and final value fetch1.runF[Eval].

val env: Eval[(FetchEnv, Post)] = getPost(1).runF[Eval]

@raulraja raulraja assigned ghost May 20, 2016
### error

Errors can also be lifted to the Fetch monad via `exception.fetch`. Note that interpreting
an errorful fetch to `Eval` will throw the exception so we won't do that:
Copy link

Choose a reason for hiding this comment

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

In the case of Eval it won't throw the exception unless accessing the value with .value, maybe we can show how the exception is conveyed on the Xor.Left when ussing the attempt combinator?

@ghost
Copy link

ghost commented May 20, 2016

Other than the comment LGTM, really awesome work 👍

@raulraja
Copy link
Contributor Author

Feel free to reword or remove that part for now if you want this to be included in the release.I won't be close to a computer this evening

@ghost
Copy link

ghost commented May 20, 2016

All right, i'll edit that part and cut another release with the new syntax and docs.

@ghost
Copy link

ghost commented May 21, 2016

:shipit:

@ghost ghost merged commit 339a162 into master May 21, 2016
@ghost ghost deleted the rr-fetch-syntax branch May 21, 2016 12:00
This pull request was closed.
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

1 participant