Suppose I have a class defined as
case class MyClass(myArray: Array[Int])
I want to only allow instances where the myArray parameter is of a specific length, say 3.
- Can I enforce that
myArray.size == 3at type/compile level? - Would it be different with another collection? (say, an immutable list)
The only way I found to this is via a smart constructor at runtime, checking the size of myArray and failing - using for instance require.