Default Sequence type

This is a very opinion based question. So, here is my opinionated answer.

In general I do not like Seq, both as a type and as a builder of collections, because it tells you very little about the runtime behaviour of the concrete collection; this provides an excellent discussion about that problem.

Thus, I prefer to use concrete types for most of my code. And here is my list of used types.

  • List as my general collection type, I use it 90% of the time. It is easy to reason about how you should use it. Also, perfect for tail-recursive functions.
  • ArraySeq for when I need fast index access or I am building something that will be passed to a Java method which expects an Array.
  • Set when I require uniqueness and fast existence check.
  • Map when I need a to get value given some key.
  • LazyList when I need a simple lazy and maybe infinite collection. (it’s unfold method is very useful).
  • mutable.ListBuilder when, for performance reasons, I need to build a List imperatively.

(If you are in 2.12 change LazyList with Stream and ArraySeq with Vector)

Outside of the stdlib.

  • cats.data.NonEmptyChain when I need a non-empty collection with fast append. (usually used to collect errors).
  • fs2.Stream when I need a more robust and async streaming collection.

And when I want to write a generic method that accepts any collection in the stdlib. I would use TraversableOnce to get an Iterator.
BTW, I also use Iterators internally in some function I chain a lot of transformations, to make all them lazy.

And that is it. Hope it helps.
As I said, this is just my opinion and preferences.
I recommend you to wait to see what do other people say about this. Take that, together with your own experience to form your own opinion.

2 Likes