Say I have a trait
sealed trait Expr[-InT, +OutT] {
def apply(lhs: InT): OutT
}
I want to create a subtype Andcontravariant in InT. Should I implement it like this (1):
type BExpr[-InT] = Expr[InT, Boolean]
final case class And[-InT](exp: BExpr[InT], exps: BExpr[InT]*) extends BExpr[InT] {
def apply(lhs: InT) = exps.foldLeft(exp.apply(lhs))(_ & _(lhs))
}
Or is the following (2) sufficient?
type BExpr[InT] = Expr[InT, Boolean]
final case class And[InT](exp: BExpr[InT], exps: BExpr[InT]*) extends BExpr[InT] {
def apply(lhs: InT) = exps.foldLeft(exp.apply(lhs))(_ & _(lhs))
}
thank
source
share