Hey What are you thought on using `Collection` typ...
# getting-started
i
Hey What are you thought on using
Collection
type? Fine / Not Fine? and Why?
Copy code
val modifiers: Collection<Modifier> = emptyList()
t
Depends strongly on use case. For example, if you want to make many
contains
calls on large collection, than it's better to convert it to some set implementation first, as some Collection implementation may be not efficient for that. But if you just want to write a function that would iterate over elements and do whatever, than it would be better to accept a `Collection`(or even
Sequence
), to remove the need of conversion of an arbitrary type of collection the caller uses to one that you use.
s
Collection
has a
size
, which `Iterable`/`Sequence` doesn't.
List
provides an order of elements on top of
Collection
.
Set
provides a uniqueness guarantee on top of
Collection
.
Collection
would often be good enough (it's nice to iterate and to have the size, if only for log messages or something). But
List
is shorter to write, so I mostly use
List
even though I very often don't need any specific order 😅