From what I have read, one should prefer to use generic Seq when defining sequences instead of specific implementations such as List
or Vector
.
Though I have parts of my code when a sequence will be used mostly for full traversal (mapping, filtering, etc) and some parts of my code where the same sequence will be used for indexing operations (indexOf, lastIndexWhere).
In the first case, I think it is better to use LinearSeq
(implem is List
) whereas in the second case it is better to use IndexedSeq
(implem is Vector
).
My question is: do I need to explicitly call the conversion method toList
and toIndexedSeq
in my code or is the conversion done under the hood in an intelligent manner ? If I use these conversions, is it a penalty for performance when going back and forth between IndexedSeq
and LinearSeq
?
Thanks in advance