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

Freestyle Effects for @tagless #507

Merged
merged 9 commits into from
Jan 12, 2018
Merged

Conversation

juanpedromoreno
Copy link
Contributor

@juanpedromoreno juanpedromoreno commented Jan 12, 2018

This PR brings support for freestyle-effects for @tagless final encoding.

From now on, asyncCatsEffect and asyncGuava have been moved to freestyle.async (both async integrations are not really tied to free.

Releases a new minor version due to the breaking changes in this PR: 0.6.0.

trait Implicits {
implicit def freeStyleEitherMHandler[M[_]](
implicit ME: MonadError[M, E]): EitherM.Handler[M] = new EitherM.Handler[M] {
def either[A](fa: Either[E, A]): M[A] = fa.fold(ME.raiseError[A], ME.pure[A])
Copy link
Member

Choose a reason for hiding this comment

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

This can be ME.fromEither(fa)


implicit def freeStyleErrorMHandler[M[_]](
implicit ME: MonadError[M, Throwable]): ErrorM.Handler[M] = new ErrorM.Handler[M] {
def either[A](fa: Either[Throwable, A]): M[A] = fa.fold(ME.raiseError[A], ME.pure[A])
Copy link
Member

Choose a reason for hiding this comment

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

This could also be ME.fromEither(fa).


final class FutureOps[A](f: Future[A]) {

def to[F[_]](implicit AC: AsyncContext[F], E: ExecutionContext): F[A] = future2AsyncM[F, A](f)
Copy link
Member

Choose a reason for hiding this comment

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

Personally I think I would call this unsafeTo, but the AsyncM type class has no real "suspension" guarantees.
We could implement it more safely for Eval[Future[A]] or a method which takes => Future[A].

We just have to remember that when we want to end up in something like monix Task or cats.effect.IO, this to method is probably not the best route.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, I've just deprecated it in 9acae08

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good. Created #509

@juanpedromoreno juanpedromoreno merged commit f4fba80 into master Jan 12, 2018
@juanpedromoreno juanpedromoreno deleted the jp-freestyle-effects-tagless branch January 12, 2018 13:07
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.

4 participants