scala - trait Enumeratee is invariant in type From when using ADT -
i trying compose enumeratee.grouped
, enumeratee.filter
make new enumeratee running variance issue. input , output types of enumeratee adts , following error.
<console>:24: error: type mismatch; found : play.api.libs.iteratee.enumeratee[outputtype,outputtype] required: play.api.libs.iteratee.enumeratee[product serializable outputtype,outputtype] note: outputtype >: product serializable outputtype, trait enumeratee invariant in type from. may wish define -from instead. (sls 4.5)
i have recreated issue smaller example here (i understand example rewritten enumeratee.collect
however, unless there way combine enumeratee.grouped
, enumeratee.filter
not me.)
import play.api.libs.iteratee.enumeratee import scala.concurrent.executioncontext.implicits.global sealed abstract class inputtype case class inputa(counter: int) extends inputtype case object inputb extends inputtype sealed abstract class outputtype case class outputa(msg: string) extends outputtype case object outputb extends outputtype val e: enumeratee[inputtype, outputtype] = enumeratee.map[inputtype] { case inputa(counter) => outputa(counter.tostring) case inputb => outputb } compose enumeratee.filter[outputtype] { case outputa("4") => false case _ => true }
i can't redefine from
type on enumeratee -from
compiler error suggests because play library. limitation of library cannot use adts when composing enumeratees? or there better approach use case (put classtag
somewhere, write functionality way, etc...)?
i found solution seems ok. if change enumeratee.map[inputtype]
enumeratee.map[inputtype].apply[outputtype]
inferencer gets invariant type , compiles fine.
val e: enumeratee[inputtype, outputtype] = enumeratee.map[inputtype].apply[outputtype] { case inputa(counter) => outputa(counter.tostring) case inputb => outputb }
Comments
Post a Comment