Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scala variable number of generic types in class

I'm working with scala and scalaStorm for a project, i'm currently using velvia's scalastorm library from github (https://github.com/velvia/ScalaStorm), and i'm trying to enrich it. I want to add type safety to storm tuple's that are by default all java Object. In storm there are entities called bolts that take tuple as input and output other tuples. I want to do something like this:

class StormBolt[T*][K*]{
}

So I can write directly:

class MyBolt[Int, Date, String][Int, String]{
}

I didn't find anything that let's me do this in some way. I appreciate any tip in implementing such feature! Adding type safety to the library wouldn't be a shame! Thank you

like image 478
tmnd91 Avatar asked Dec 21 '14 00:12

tmnd91


1 Answers

You can do it with simple generic types or use HList from shapeless(https://github.com/milessabin/shapeless/wiki/Feature-overview:-shapeless-2.0.0#heterogenous-lists)

trait StormBolt[T, K] {
}

trait MyBolt extends StormBolt[(Int, Date, String), (Int, String)]

or with shapeless

trait StormBolt[T <: HList, K <: HList] {
}

trait MyBolt extends StormBolt[Int :: Date :: String :: HNil, Int :: String :: HNil] {
}

with shapeless you can get lot's of cool features, you can take a look at feature overview, maybe you'll find some of them useful

like image 67
Eugene Zhulenev Avatar answered Oct 26 '22 15:10

Eugene Zhulenev