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
SIP-??? created pending: Implicits in for comprehensions #417
Conversation
Thank you both for taking a look at this! I'm not sure how this is making I'm not actually using flatten, I'm translating it to ".flatMap { x => x }" where x is fresh in order to avoid adding any requirements on the source data types for generators. Today they are only required to provide My next steps are to read the quasiquotes and comprehensive comprehensions docs mentioned by @retronym and figure out how that impacts my work and try making the changes suggested by @adriaanm. This may take me a few days. I've also updated the code: I've squashed my commits and moved them to a new branch sip24a based on 2.12.x to be more modern (and added some more tests). I've changed the |
This depends on the trait M[A] {
def map[B](a: A => B): M[B]
def flatMap[B](a: A => M[B]): M[B]
def filter(f: A => Boolean): M[A]
}
object Test {
def guard = true
def testOk (m: M[String]) = m.filter(_ => guard).map(x => x)
def testFail(m: M[String]) = m.flatMap(x => if (guard) Some(x) else None)
}
The current encoding using |
If people are okay with broadening the scope per the suggestion from @densh then the desugaring rules become much simpler and the Otherwise, I'll look for alternatives that do not depend on |
+1 to the generalization |
Have emailed and tweeted Harold to glean continuing interest in pursuing this. Will likely move to dormant in the next SIP/SLIP committee meeting if nothing heard back. |
I've closed this PR since I haven't found time to pursue the generalization suggested by @retronym and I think that that is the right way to proceed. |
FYI nowadays you can get the same functionality by using https://github.com/oleg-py/better-monadic-for#define-implicits-in-for-comprehensions-or-matches |
I'd like to propose SIP-24: Implicits in for comprehensions.