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

Future instance #4

Closed
mfirry opened this issue Jun 19, 2019 · 3 comments
Closed

Future instance #4

mfirry opened this issue Jun 19, 2019 · 3 comments

Comments

@mfirry
Copy link

mfirry commented Jun 19, 2019

Hi and thanks for this (and everything else you work on).

Coming back from Scala Days, I was experimenting a bit with this sort of things and came out with a silly instance for Future along these lines:

delegate for Monad[Future] {
  def (fa: Future[A]) map[A, B](f: A => Future[B]): Future[B] =
    fa.map(f)
}

My question is how would one go about passing the required ExecutionContext.

Thanks!

@mfirry
Copy link
Author

mfirry commented Sep 10, 2019

Hi. I was wondering if anybody had time to help me with this. Otherwise I'll close it, no problem.

@ChristopherDavenport
Copy link
Member

implicit val ec = scala.concurrent.ExecutionContext.global

delegate for Monad[Future] {
  def (fa: Future[A]) map[A, B](f: A => Future[B]): Future[B] =
    fa.map(f)
}

Future is a monad, I truly recommend trying to to avoid using at a Monad as how its typically used, side-effecting is not.

So this is only useful when used in a way future is never actually used as.

Otherwise I think future would need here as well to rely on scala 2 mechanisms at the implicit context is not available.

@mfirry
Copy link
Author

mfirry commented Sep 10, 2019

Thanks so much Christopher!

@mfirry mfirry closed this as completed Sep 10, 2019
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

No branches or pull requests

2 participants