Thread
#stdlib
    mbonnin

    mbonnin

    1 year ago
    Is there a specific reason why
    Set<T>.map {}
    returns a
    List
    and not a
    Set
    ?
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    1 year ago
    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.
    mbonnin

    mbonnin

    1 year ago
    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

    Ruckus

    1 year ago
    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.
    mbonnin

    mbonnin

    1 year ago
    @Ruckus right, makes sense
    Well, it could return a
    Set
    of a different size I guess
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    1 year ago
    A set can’t contain duplicate values, by definition
    mbonnin

    mbonnin

    1 year ago
    Mmm right, and since the order or iteration is not defined, what data is going to be dropped would not be defined either
    j

    jw

    1 year ago
    If you want a set, use mapTo and supply one