Get started

PersistentList

A generic persistent ordered collection of elements that supports adding and removing elements.

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

Type Parameters

E

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

Inheritors

Types

Link copied to clipboard

A generic builder of the persistent list. Builder exposes its modification operations through the MutableList interface.

Functions

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

Returns a new persistent list with the specified element appended.

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

Returns a new persistent list with elements of the specified elements collection appended, or this instance if the specified collection is empty.

Link copied to clipboard
open fun addingAllAt(index: Int, c: Collection<E>): PersistentList<E>

Returns a new persistent list with the specified c collection inserted at the specified index, or this instance if the specified collection is empty.

Link copied to clipboard
open fun addingAt(index: Int, element: E): PersistentList<E>

Returns a new persistent list with the specified element inserted at the specified index.

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

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

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

Returns an empty persistent list.

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

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

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

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

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

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

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

Returns a new persistent list containing all elements of this list 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> PersistentList<T>.mutate(mutator: (MutableList<T>) -> Unit): PersistentList<T>

Returns a new persistent list 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> PersistentList<E>.plus(element: E): PersistentList<E>

Returns a new persistent list with the specified element appended.

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

Returns a new persistent list with elements of the specified elements array appended, or this instance if the specified array is empty.

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

Returns a new persistent list with elements of the specified elements collection appended, or this instance if the specified collection is empty.

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

Returns a new persistent list with elements of the specified elements sequence appended, or this instance if the specified sequence is empty.

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

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

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

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

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

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

Link copied to clipboard
open fun removingAt(index: Int): PersistentList<E>

Returns a new persistent list with the element at the specified index removed.

Link copied to clipboard
open fun replacingAt(index: Int, element: E): PersistentList<E>

Returns a new persistent list with the element at the specified index replaced with the specified element.

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

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