I want a set that retains insertion order, is a so...
# announcements
b
I want a set that retains insertion order, is a sorted set the wrong type?
d
You should call toSet() instead of toSortedSet().
👍 2
As the name implies, toSortedSet() will sort the items
👍 3
k
hm does .toSet guarantee insertion order?
d
Try and test it, only then you will know.
b
there is no toLinkedHashSet right?
s
documentation of `toSet()`: The returned set preserves the element iteration order of the original collection.
👍 3
I figure that is what you want
b
so toSet() doesn’t return a Set but a LinkedHashSet?
ha, yeah
Copy code
if (this is Collection) {
    return when (size) {
        0 -> emptySet()
        1 -> setOf(if (this is List) this[0] else iterator().next())
        else -> toCollection(LinkedHashSet<T>(mapCapacity(size)))
    }
}
return toCollection(LinkedHashSet<T>()).optimizeReadOnlySet()
the naming is really wrong
e
Is it wrong? Set is the Interface, LinkedHashSet is the implementation. As it should.