MutableVector

Class

Common
public class MutableVector<T>
@PublishedApi
internal constructor(@PublishedApi @JvmField internal var content: Array<T?>, size: Int) :
    RandomAccess

A MutableList-like structure with a simplified interface that offers faster access than ArrayList.

Functions

public fun add(element: T): Boolean

Adds element to the MutableVector and returns true.

public fun add(index: Int, element: T)

Adds element to the MutableVector at the given index, shifting over any elements that are in the way.

public fun addAll(index: Int, elements: List<T>): Boolean

Adds all elements to the MutableVector at the given index, shifting over any elements that are in the way.

public fun addAll(index: Int, elements: MutableVector<T>): Boolean

Adds all elements to the MutableVector at the given index, shifting over any elements that are in the way.

public inline fun addAll(elements: List<T>): Boolean

Adds all elements to the end of the MutableVector and returns true if the MutableVector was changed.

public inline fun addAll(elements: MutableVector<T>): Boolean

Adds all elements to the end of the MutableVector and returns true if the MutableVector was changed.

public fun addAll(@Suppress("ArrayReturn") elements: Array<T>): Boolean

Adds all elements to the end of the MutableVector and returns true if the MutableVector was changed.

public fun addAll(index: Int, elements: Collection<T>): Boolean

Adds all elements to the MutableVector at the given index, shifting over any elements that are in the way.

public fun addAll(elements: Collection<T>): Boolean

Adds all elements to the end of the MutableVector and returns true if the MutableVector was changed.

public inline fun any(predicate: (T) -> Boolean): Boolean

Returns true if any of the elements give a true return value for predicate.

public inline fun reversedAny(predicate: (T) -> Boolean): Boolean

Returns true if any of the elements give a true return value for predicate while iterating in the reverse order.

public fun asMutableList(): MutableList<T>

Returns MutableList interface access to the MutableVector.

public fun clear()

Removes all elements in the MutableVector.

public operator fun contains(element: T): Boolean

Returns true if the MutableVector contains element or false otherwise.

public fun containsAll(elements: List<T>): Boolean

Returns true if the MutableVector contains all elements in elements or false if one or more are missing.

public fun containsAll(elements: Collection<T>): Boolean

Returns true if the MutableVector contains all elements in elements or false if one or more are missing.

public fun containsAll(elements: MutableVector<T>): Boolean

Returns true if the MutableVector contains all elements in elements or false if one or more are missing.

public fun contentEquals(other: MutableVector<T>): Boolean

Returns true if the contents of the MutableVector are the same or false if there is any difference. This uses equality comparisons on each element rather than reference equality.

public inline fun ensureCapacity(capacity: Int)

Ensures that there is enough space to store capacity elements in the MutableVector.

public fun first(): T

Returns the first element in the MutableVector or throws a NoSuchElementException if it isEmpty.

public inline fun first(predicate: (T) -> Boolean): T

Returns the first element in the MutableVector for which predicate returns true or throws NoSuchElementException if nothing matches.

public inline fun firstOrNull(): T?

Returns the first element in the MutableVector or null if it isEmpty.

public inline fun firstOrNull(predicate: (T) -> Boolean): T?

Returns the first element in the MutableVector for which predicate returns true or returns null if nothing matches.

public inline fun <R> fold(initial: R, operation: (acc: R, T) -> R): R

Accumulates values, starting with initial, and applying operation to each element in the MutableVector in order.

public inline fun <R> foldIndexed(initial: R, operation: (index: Int, acc: R, T) -> R): R

Accumulates values, starting with initial, and applying operation to each element in the MutableVector in order.

public inline fun <R> foldRight(initial: R, operation: (T, acc: R) -> R): R

Accumulates values, starting with initial, and applying operation to each element in the MutableVector in reverse order.

public inline fun <R> foldRightIndexed(initial: R, operation: (index: Int, T, acc: R) -> R): R

Accumulates values, starting with initial, and applying operation to each element in the MutableVector in reverse order.

public inline fun forEach(block: (T) -> Unit)

Calls block for each element in the MutableVector, in order.

public inline fun forEachIndexed(block: (Int, T) -> Unit)

Calls block for each element in the MutableVector along with its index, in order.

public inline fun forEachReversed(block: (T) -> Unit)

Calls block for each element in the MutableVector in reverse order.

public inline fun forEachReversedIndexed(block: (Int, T) -> Unit)

Calls block for each element in the MutableVector along with its index, in reverse order.

public inline operator fun get(index: Int): T

Returns the element at the given index.

public fun indexOf(element: T): Int

Returns the index of element in the MutableVector or -1 if element is not there.

public inline fun indexOfFirst(predicate: (T) -> Boolean): Int

Returns the index if the first element in the MutableVector for which predicate returns true.

public inline fun indexOfLast(predicate: (T) -> Boolean): Int

Returns the index if the last element in the MutableVector for which predicate returns true.

public inline fun isEmpty(): Boolean

Returns true if the MutableVector has no elements in it or false otherwise.

public inline fun isNotEmpty(): Boolean

Returns true if there are elements in the MutableVector or false if it is empty.

public fun last(): T

Returns the last element in the MutableVector or throws a NoSuchElementException if it isEmpty.

public inline fun last(predicate: (T) -> Boolean): T

Returns the last element in the MutableVector for which predicate returns true or throws NoSuchElementException if nothing matches.

public fun lastIndexOf(element: T): Int

Returns the index of the last element in the MutableVector that is the same as element or -1 if no elements match.

public inline fun lastOrNull(): T?

Returns the last element in the MutableVector or null if it isEmpty.

public inline fun lastOrNull(predicate: (T) -> Boolean): T?

Returns the last element in the MutableVector for which predicate returns true or returns null if nothing matches.

public inline fun <reified R> map(transform: (T) -> R): Array<R>

Returns an Array of results of transforming each element in the MutableVector. The Array will be the same size as this.

public inline fun <reified R> mapIndexed(transform: (index: Int, T) -> R): Array<R>

Returns an Array of results of transforming each element in the MutableVector. The Array will be the same size as this.

public inline fun <reified R> mapIndexedNotNull(
        transform: (index: Int, T) -> R?
    ): MutableVector<R>

Returns an MutableVector of results of transforming each element in the MutableVector, excluding those transformed values that are null.

public inline fun <reified R> mapNotNull(transform: (T) -> R?): MutableVector<R>

Returns an MutableVector of results of transforming each element in the MutableVector, excluding those transformed values that are null.

public inline operator fun plusAssign(element: T)

add element to the MutableVector.

public inline operator fun minusAssign(element: T)

remove element from the MutableVector

public fun remove(element: T): Boolean

Removes element from the MutableVector. If element was in the MutableVector and was removed, true will be returned, or false will be returned if the element was not found.

public fun removeAll(elements: List<T>): Boolean

Removes all elements from the MutableVector and returns true if anything was removed.

public fun removeAll(elements: MutableVector<T>): Boolean

Removes all elements from the MutableVector and returns true if anything was removed.

public fun removeAll(elements: Collection<T>): Boolean

Removes all elements from the MutableVector and returns true if anything was removed.

public fun removeAt(index: Int): T

Removes the element at the given index and returns it.

public fun removeRange(start: Int, end: Int)

Removes items from index start (inclusive) to end (exclusive).

public inline fun removeIf(predicate: (T) -> Boolean)

Removes items that satisfy predicate

public fun retainAll(elements: Collection<T>): Boolean

Keeps only elements in the MutableVector and removes all other values.

public operator fun set(index: Int, element: T): T

Sets the value at index to element.

public fun sortWith(comparator: Comparator<T>)

Sorts the MutableVector using comparator to order the items.

public inline fun sumBy(selector: (T) -> Int): Int

Returns the sum of all values produced by selector for each element in the MutableVector.