How to require typesafe constant-size array in scala?
问题 I need something like this: def encryptBlock(arr: FixedArray[Size16]) = ??? val blocks = arr.splitFixed[Size16] val encrypted = encryptBlock(FixedArray[Size16]()) So, to be sure that I receive only 128-bit array as input. 回答1: Shapeless can do that for seqs: import shapeless._ import nat._ import syntax.sized._ scala> def func(l: Sized[List[Int], _3]) = l func: (l: shapeless.Sized[List[Int],shapeless.nat._3])shapeless.Sized[List[Int],shapeless.nat._3] scala> List(1,2,3,4,5,6).grouped(3).map(_