Get started

PersistentSet

A generic persistent unordered collection of elements that does not support duplicate elements, and supports adding and removing elements.

Modification operations return new instances of the persistent set with the modification applied.

Type Parameters

E

the type of elements contained in the set. The persistent set is covariant on its element type.

Types

Link copied to clipboard

A generic builder of the persistent set. Builder exposes its modification operations through the MutableSet interface.

Functions

Link copied to clipboard
open override fun adding(element: E): PersistentSet<E>

Returns a new persistent set with the specified element added, or this instance if it already contains the element.

Link copied to clipboard
open override fun addingAll(elements: Collection<E>): PersistentSet<E>

Returns a new persistent set with elements of the specified elements collection added, or this instance if it already contains every element of the specified collection.

Link copied to clipboard
abstract override fun builder(): PersistentSet.Builder<E>

Returns a new builder with the same contents as this collection.

Link copied to clipboard
open override fun cleared(): PersistentSet<E>

Returns an empty persistent set.

Link copied to clipboard
infix fun <E> PersistentSet<E>.intersect(elements: Iterable<E>): PersistentSet<E>

Returns a new persistent set with elements in this set that are also contained in the specified elements collection, or this instance if no modifications were made in the result of this operation.

Link copied to clipboard
inline operator fun <E> PersistentSet<E>.minus(element: E): PersistentSet<E>

Returns a new persistent set with the specified element removed, or this instance if there is no such element in this set.

operator fun <E> PersistentSet<E>.minus(elements: Array<out E>): PersistentSet<E>

Returns a new persistent set containing all elements of this set except the elements contained in the specified elements array, or this instance if there are no elements to remove.

operator fun <E> PersistentSet<E>.minus(elements: Iterable<E>): PersistentSet<E>

Returns a new persistent set containing all elements of this set except the elements contained in the specified elements collection, or this instance if there are no elements to remove.

operator fun <E> PersistentSet<E>.minus(elements: Sequence<E>): PersistentSet<E>

Returns a new persistent set containing all elements of this set except the elements contained in the specified elements sequence, or this instance if there are no elements to remove.

Link copied to clipboard
inline fun <T> PersistentSet<T>.mutate(mutator: (MutableSet<T>) -> Unit): PersistentSet<T>

Returns a new persistent set with the provided modifications applied, or this instance if no modifications were made in the result of this operation.

Link copied to clipboard
inline operator fun <E> PersistentSet<E>.plus(element: E): PersistentSet<E>

Returns a new persistent set with the specified element added, or this instance if it already contains the element.

operator fun <E> PersistentSet<E>.plus(elements: Array<out E>): PersistentSet<E>

Returns a new persistent set with elements of the specified elements array added, or this instance if it already contains every element of the specified array.

operator fun <E> PersistentSet<E>.plus(elements: Iterable<E>): PersistentSet<E>

Returns a new persistent set with elements of the specified elements collection added, or this instance if it already contains every element of the specified collection.

operator fun <E> PersistentSet<E>.plus(elements: Sequence<E>): PersistentSet<E>

Returns a new persistent set with elements of the specified elements sequence added, or this instance if it already contains every element of the specified sequence.

Link copied to clipboard
open override fun removing(element: E): PersistentSet<E>

Returns a new persistent set with the specified element removed, or this instance if there is no such element in this set.

Link copied to clipboard
open override fun removingAll(predicate: (E) -> Boolean): PersistentSet<E>

Returns a new persistent set with elements matching the specified predicate removed, or this instance if no elements match the predicate.

open override fun removingAll(elements: Collection<E>): PersistentSet<E>

Returns a new persistent set containing all elements of this set except the elements contained in the specified elements collection, or this instance if there are no elements to remove.

Link copied to clipboard
open override fun retainingAll(elements: Collection<E>): PersistentSet<E>

Returns a new persistent set with elements in this set that are also contained in the specified elements collection, or this instance if no modifications were made in the result of this operation.