【发布时间】:2014-10-03 00:55:04
【问题描述】:
我有这段代码想要改进:
sealed abstract class A
case class B() extends A
case class C() extends A
case class D() extends A
case class Foo[+T <: A](a: T)
/** Puts instances that match Foo(B()) in the first list and everything else,
* i.e. Foo(C()) and Foo(D()), in the second list. */
def partition(foos: List[Foo[_ <: A]]): (List[Foo[B]], List[Foo[_ <: A]]) = {
// ...
}
我想在以下方面对此进行改进:
- 我能否更改
partition的返回类型,使其表明第二个列表中没有Foo[B]? - 我可以去掉
Foo的类型参数T(即将Foo更改为case class Foo(a: A))并仍然用相同的类型保证声明partition吗? (显然,它必须返回不同于(List[Foo], List[Foo])的内容。)
P.S.:如果“shapeless”标签与这个问题无关,请告诉我。
【问题讨论】: