Scala 2.10.1中的新的desugaring行为
发布时间:2020-12-16 09:47:42 所属栏目:安全 来源:网络整理
导读:假设我有这个monadic类: case class Foo[A](xs: List[A]) { def map[B](f: A = B) = Foo(xs map f) def flatMap[B](f: A = Foo[B]) = Foo(xs flatMap f.andThen(_.xs)) def withFilter(p: A = Boolean) = { println("Filtering!") Foo(xs filter p) }} 以下
假设我有这个monadic类:
case class Foo[A](xs: List[A]) { def map[B](f: A => B) = Foo(xs map f) def flatMap[B](f: A => Foo[B]) = Foo(xs flatMap f.andThen(_.xs)) def withFilter(p: A => Boolean) = { println("Filtering!") Foo(xs filter p) } } 以下是来自2.10.0 REPL会话: scala> for { (a,b) <- Foo(List(1 -> "x")) } yield a res0: Foo[Int] = Foo(List(1)) 这里有同样的事情在2.10.1: scala> for { (a,b) <- Foo(List(1 -> "x")) } yield a Filtering! res0: Foo[Int] = Foo(List(1)) 这是完全意想不到的(对我),并导致特别混乱的错误,在过滤需要额外的约束(如Scalaz的 我没能在2.10.1 release notes找到任何讨论这个变化。有人可以指出在哪里和为什么这种新的desug行为被介绍? 解决方法
这个故事比那个更复杂,事实上是一个2.10.0的回归,插在那里。
“no-withFilter”行为在c82ecab中引入,并且由于像SI-6968这样的事情,这部分恢复了#1893.进一步的适应(SI-6646,SI-7183) 你要找的外卖句是:
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |