收缩案例类的宏

时间:2015-02-27 10:39:38

标签: scala shrink scalacheck

我正在为我的案例类实施Shrink instances。在我看来,宏可以做到这一点。有人实施了吗?

1 个答案:

答案 0 :(得分:3)

是的,他们有!对于TypeClassshapeless-contrib an instance Shrink scala> import org.scalacheck._ import org.scalacheck._ scala> case class Foo(s: String, i: Int) defined class Foo scala> val unshrunk = Foo("This is a very long string", 1000) unshrunk: Foo = Foo(This is a very long string,1000) scala> implicitly[Shrink[Foo]].shrink(unshrunk) // boring default instance res0: Stream[Foo] = Stream() scala> import shapeless.contrib.scalacheck._ import shapeless.contrib.scalacheck._ scala> implicitly[Shrink[Foo]].shrink(unshrunk) // interesting instance res1: Stream[Foo] = Stream(Foo(This is a ver,1000), ?) {/ 3}}

Generic

宏支持这一点,但只支持Shapeless用于其{{1}}机器的宏。