Let's say I have some code that uses List
def processList(input: List[Int]): List[Int]
I want to replace list with other collection types, like Vector.
Is there a way to define a type constructor so that I can write something like
type SomeCollection[_] = List[_]
def processList(input: SomeCollection[Int]): SomeCollection[Int]
Now I have written processList in terms of SomeCollection. To change SomeCollection to Vector, I just change the type alias, and everywhere in the codebase where I use SomeCollection, I now use Vector. Like so:
type SomeCollection[_] = Vector[_]
def processList(input: SomeCollection[Int]): SomeCollection[Int]
This way, I only need to change the codebase in one place instead of everywhere.
I do not want to write
type SomeIntCollection = List[Int]
because I have connected the collection to Int type.
Is there a way?