Last active
December 14, 2015 15:18
-
-
Save vmarquez/5106252 to your computer and use it in GitHub Desktop.
Broken Scala For Comprehension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package vsxmpp | |
import scalaz.EitherT | |
import scalaz._ | |
import Scalaz._ | |
case class ABC(s:String) | |
object ABC { | |
implicit val m = new Monoid[(ABC, Int)] { | |
def zero: (ABC, Int) = (null, -1) | |
def append(f1: (ABC, Int), f2: => (ABC, Int)): (ABC, Int) = f1 | |
} | |
def BrokenMethod(): EitherT[Option, (ABC, Int), (ABC, String)] = { | |
EitherT(Some((ABC("abcData"),"Success").right)) | |
} | |
def filterComp() = | |
BrokenMethod() | |
.filter { | |
case (abc,"Success") => true | |
case _ => false | |
}.map { | |
case (abc, "Success") => "yay" | |
} | |
def forComp() = | |
for { | |
(a,b) <- BrokenMethod() //erroneous or inaccessible type | |
} yield "yay" | |
def main(args: Array[String]): Unit = { | |
val a = forComp() | |
println("a = " + a) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's a closer look at things:
Something imported from
Scalaz._
seems to be interfering with the rewriting ofwithFilter
tofilter
. Scalaz should really define awithFilter
method directly; this rewriting is a backward compatibility measure in scalac, as the rewriting of for-comprehensions changed in 2.8. Take a look at thewithFilter
implementation for, say,scala.Option
to see what they should look like.