Is there a specific reason why `Set<T>.map {...
# stdlib
m
Is there a specific reason why
Set<T>.map {}
returns a
List
and not a
Set
?
z
You can look at the definition of the extension function, I think it’s defined on
Iterable
so
List
is the return type that makes the most sense given the generic receiver.
m
Right, there's no
Set<T>.map {}
...
Only
Iterable<T>.map {}
I thought maybe there were considerations that a List is faster than a Set
r
Also, even if it was defined on
Set
, it wouldn't necessarily make sense to return a set, as we don't know if the mapping function will return unique values. So dropping data when mapping to a set should be explicit.
☝️ 8
☝🏽 1
m
@Ruckus right, makes sense
Well, it could return a
Set
of a different size I guess
z
A set can’t contain duplicate values, by definition
m
Mmm right, and since the order or iteration is not defined, what data is going to be dropped would not be defined either
j
If you want a set, use mapTo and supply one
👍 6