AtomicList

class AtomicList<E> : List<E>

A List that allows for thread safe, atomic mutation. Returned collections such as iterator and subList reference a snapshot of when they were accessed, and are not mutated when the list is.

Although mutable, this class intentionally does not implement MutableList. Mutation must use designated mutator functions (mutate, snapshotAndMutate, mutateAndSnapshot).

Constructors

Link copied to clipboard
constructor(initial: PersistentList<E>)

Construct an AtomicList with initial list.

Properties

Link copied to clipboard
open override val size: Int
Link copied to clipboard
val snapshot: ImmutableList<E>

Returns the current value of this List as an immutable snapshot.

Link copied to clipboard
val snapshots: StateFlow<ImmutableList<E>>

Returns this list as a StateFlow. Each mutation will cause a new emission on this flow.

Functions

Link copied to clipboard
open operator override fun contains(element: E): Boolean
Link copied to clipboard
open override fun containsAll(elements: Collection<E>): Boolean
Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open operator override fun get(index: Int): E
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
open override fun indexOf(element: E): Int
Link copied to clipboard
open override fun isEmpty(): Boolean
Link copied to clipboard
open operator override fun iterator(): Iterator<E>
Link copied to clipboard
open override fun lastIndexOf(element: E): Int
Link copied to clipboard
open override fun listIterator(): ListIterator<E>
open override fun listIterator(index: Int): ListIterator<E>
Link copied to clipboard
inline fun mutate(mutator: MutableList<E>.() -> Unit)

Mutates this List atomically. mutator can be evaluated multiple times if a concurrent edit occurs.

Link copied to clipboard
inline fun mutateAndSnapshot(mutator: MutableList<E>.() -> Unit): ImmutableList<E>

Mutates this List atomically and returns the new snapshot. mutator can be evaluated multiple times if a concurrent edit occurs.

Link copied to clipboard
inline fun snapshotAndMutate(mutator: MutableList<E>.() -> Unit): ImmutableList<E>

Mutates this List atomically and returns the previous snapshot. mutator can be evaluated multiple times if a concurrent edit occurs.

Link copied to clipboard
open override fun subList(fromIndex: Int, toIndex: Int): ImmutableList<E>
Link copied to clipboard
open override fun toString(): String