@@ -766,3 +766,61 @@ public fun <K, V> Map<K, V>.toPersistentHashMap(): PersistentMap<K, V>
766
766
= this as ? PersistentHashMap
767
767
? : (this as ? PersistentHashMapBuilder <K , V >)?.build()
768
768
? : PersistentHashMap .emptyOf<K , V >().putAll(this )
769
+
770
+ /* *
771
+ * Builds a new [PersistentList] by populating a [PersistentList.Builder] using the given [builderAction]
772
+ * and returning an immutable list with the same elements.
773
+ *
774
+ * The list passed as a receiver to the [builderAction] is valid only inside that function.
775
+ * Using it outside the function produces an unspecified behavior.
776
+ */
777
+ public inline fun <T > buildPersistentList (builderAction : PersistentList .Builder <T >.() -> Unit ): PersistentList <T > =
778
+ persistentListOf<T >().builder().apply (builderAction).build()
779
+
780
+ /* *
781
+ * Builds a new [PersistentSet] by populating a [PersistentSet.Builder] using the given [builderAction]
782
+ * and returning an immutable set with the same elements.
783
+ *
784
+ * The set passed as a receiver to the [builderAction] is valid only inside that function.
785
+ * Using it outside the function produces an unspecified behavior.
786
+ *
787
+ * Elements of the set are iterated in the order they were added by the [builderAction].
788
+ */
789
+ public inline fun <T > buildPersistentSet (builderAction : PersistentSet .Builder <T >.() -> Unit ): PersistentSet <T > =
790
+ persistentSetOf<T >().builder().apply (builderAction).build()
791
+
792
+ /* *
793
+ * Builds a new [PersistentSet] by populating a [PersistentSet.Builder] using the given [builderAction]
794
+ * and returning an immutable set with the same elements.
795
+ *
796
+ * The set passed as a receiver to the [builderAction] is valid only inside that function.
797
+ * Using it outside the function produces an unspecified behavior.
798
+ *
799
+ * Order of the elements in the returned set is unspecified.
800
+ */
801
+ public inline fun <T > buildPersistentHashSet (builderAction : PersistentSet .Builder <T >.() -> Unit ): PersistentSet <T > =
802
+ persistentHashSetOf<T >().builder().apply (builderAction).build()
803
+
804
+ /* *
805
+ * Builds a new [PersistentMap] by populating a [PersistentMap.Builder] using the given [builderAction]
806
+ * and returning an immutable map with the same key-value pairs.
807
+ *
808
+ * The map passed as a receiver to the [builderAction] is valid only inside that function.
809
+ * Using it outside the function produces an unspecified behavior.
810
+ *
811
+ * Entries of the map are iterated in the order they were added by the [builderAction].
812
+ */
813
+ public inline fun <K , V > buildPersistentMap (builderAction : PersistentMap .Builder <K , V >.() -> Unit ): PersistentMap <K , V > =
814
+ persistentMapOf<K , V >().builder().apply (builderAction).build()
815
+
816
+ /* *
817
+ * Builds a new [PersistentMap] by populating a [PersistentMap.Builder] using the given [builderAction]
818
+ * and returning an immutable map with the same key-value pairs.
819
+ *
820
+ * The map passed as a receiver to the [builderAction] is valid only inside that function.
821
+ * Using it outside the function produces an unspecified behavior.
822
+ *
823
+ * Order of the entries in the returned map is unspecified.
824
+ */
825
+ public inline fun <K , V > buildPersistentHashMap (builderAction : PersistentMap .Builder <K , V >.() -> Unit ): PersistentMap <K , V > =
826
+ persistentHashMapOf<K , V >().builder().apply (builderAction).build()
0 commit comments