diff --git a/core/commonMain/src/extensions.kt b/core/commonMain/src/extensions.kt index f6d75641..d179c803 100644 --- a/core/commonMain/src/extensions.kt +++ b/core/commonMain/src/extensions.kt @@ -645,11 +645,14 @@ fun CharSequence.toImmutableSet(): PersistentSet = toPersistentSet() * If the receiver is already a persistent set, returns it as is. * If the receiver is a persistent set builder, calls `build` on it and returns the result. * - * Elements of the returned set are iterated in the same order as in this collection. + * * If the receiver is not a persistent set builder, + * elements of the returned set are iterated in the same order as in this collection. + * Otherwise the order depends on the persistent set builder implementation. + */ fun Iterable.toPersistentSet(): PersistentSet = - this as? PersistentOrderedSet - ?: (this as? PersistentOrderedSetBuilder)?.build() + this as? PersistentSet + ?: (this as? PersistentSet.Builder)?.build() ?: PersistentOrderedSet.emptyOf() + this /** @@ -715,11 +718,13 @@ fun Map.toImmutableMap(): ImmutableMap * If the receiver is already a persistent map, returns it as is. * If the receiver is a persistent map builder, calls `build` on it and returns the result. * - * Entries of the returned map are iterated in the same order as in this map. + * If the receiver is not a persistent map builder, + * entries of the returned map are iterated in the same order as in this map. + * Otherwise the order depends on the persistent map builder implementation. */ fun Map.toPersistentMap(): PersistentMap - = this as? PersistentOrderedMap - ?: (this as? PersistentOrderedMapBuilder)?.build() + = this as? PersistentMap + ?: (this as? PersistentMap.Builder)?.build() ?: PersistentOrderedMap.emptyOf().putAll(this) /**