The method map
requires two type arguments (element type and the type of returned collection, which might depend in a non-trivial way on the element type). Both arguments are usually omitted.
You don't need new
to instantiate case classes. Indeed, the Player
companion object Player
can be used as a function from Int
to Player
.
Applying these two hints gives you:
Stream.range(1, 12).map(Player)
However, it is a bit strange that you are using Stream
for a tiny collection with a fixed number of elements. A List
or Vector
would seem much more appropriate here, so you might even try something like
1 to 12 map Player
If you are wondering why map
takes two type parameters, here are few examples:
// return `Iterable` instead of `Stream`
Stream.range(1, 12).map[Player, Iterable[Player]](Player)
// return `Iterable` instead of `Stream` and `Any` instead of `Player`
Stream.range(1, 12).map[Player, Iterable[Any]](Player)
This will produce values with the specified return types (e.g. Iterable[Player]
instead of Stream[Player]
). Thus, the second type argument can be used to control the return type. Normally, you don't need it, and the appropriate type is returned automatically.