I have trait like this I can create pipe objects like Pipe[String,Int], Pipe[String,String],Pipe[(String,Double),String]
trait Pipe[In,Out] {
def apply(rdd: RDD[In]): RDD[Out]
}
Is there any way to create trait Pipe like this
trait Pipe {
def apply[In,Out](rdd: RDD[In]): RDD[Out]
}
then I can use Pipe objects without giving any parameters.But I couldn't create this trait objects.
In order to produce an RDD[Out]
from an RDD[In]
you need to know how to transform one into the other. This transformation is what would hold the Out
parameter, eg:
trait Pipe[In,Out] {
def apply(rdd: RDD[In]): RDD[Out] = rddTransformer(rdd)
private def rddTransformer: RDD[In] => RDD[Out]
}
If you know at compile time what Out
type you want for some In
types, then look into Functional Dependencies: https://milessabin.com/blog/2011/07/16/fundeps-in-scala/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.