LongArray
For Common, JVM, JS
An array of longs. When targeting the JVM, instances of this class are represented as long[]
.
For Native
An array of longs.
Constructors
Properties
size
Returns the number of elements in the array.
val size: Int
Functions
get
Returns the array element at the given index. This method can be called using the index operator.
operator fun get(index: Int): Long
iterator
Creates an iterator over the elements of the array.
operator fun iterator(): LongIterator
Extension Properties
Extension Functions
associateBy
Returns a Map containing the elements from the given array indexed by the key returned from keySelector function applied to each element.
Returns a Map containing the values provided by valueTransform and indexed by keySelector functions applied to elements of the given array.
associateByTo
Populates and returns the destination mutable map with key-value pairs, where key is provided by the keySelector function applied to each element of the given array and value is the element itself.
fun <K, M : MutableMap<in K, in Long>> LongArray.associateByTo(
destination: M,
keySelector: (Long) -> K
): M
Populates and returns the destination mutable map with key-value pairs, where key is provided by the keySelector function and and value is provided by the valueTransform function applied to elements of the given array.
fun <K, V, M : MutableMap<in K, in V>> LongArray.associateByTo(
destination: M,
keySelector: (Long) -> K,
valueTransform: (Long) -> V
): M
associateTo
Populates and returns the destination mutable map with key-value pairs provided by transform function applied to each element of the given array.
fun <K, V, M : MutableMap<in K, in V>> LongArray.associateTo(
destination: M,
transform: (Long) -> Pair<K, V>
): M
associateWith
Returns a Map where keys are elements from the given array and values are produced by the valueSelector function applied to each element.
associateWithTo
Populates and returns the destination mutable map with key-value pairs for each element of the given array, where key is the element itself and value is provided by the valueSelector function applied to that key.
fun <V, M : MutableMap<in Long, in V>> LongArray.associateWithTo(
destination: M,
valueSelector: (Long) -> V
): M
asULongArray
Returns an array of type ULongArray, which is a view of this array where each element is an unsigned reinterpretation of the corresponding element of this array.
fun LongArray.asULongArray(): ULongArray
component1
Returns 1st element from the array.
operator fun LongArray.component1(): Long
component2
Returns 2nd element from the array.
operator fun LongArray.component2(): Long
component3
Returns 3rd element from the array.
operator fun LongArray.component3(): Long
component4
Returns 4th element from the array.
operator fun LongArray.component4(): Long
component5
Returns 5th element from the array.
operator fun LongArray.component5(): Long
elementAtOrElse
Returns an element at the given index or the result of calling the defaultValue function if the index is out of bounds of this array.
fun LongArray.elementAtOrElse(
index: Int,
defaultValue: (Int) -> Long
): Long
filterIndexedTo
Appends all elements matching the given predicate to the given destination.
fun <C : MutableCollection<in Long>> LongArray.filterIndexedTo(
destination: C,
predicate: (index: Int, Long) -> Boolean
): C
filterNotTo
Appends all elements not matching the given predicate to the given destination.
fun <C : MutableCollection<in Long>> LongArray.filterNotTo(
destination: C,
predicate: (Long) -> Boolean
): C
filterTo
Appends all elements matching the given predicate to the given destination.
fun <C : MutableCollection<in Long>> LongArray.filterTo(
destination: C,
predicate: (Long) -> Boolean
): C
firstOrNull
Returns the first element, or null
if the array is empty.
fun LongArray.firstOrNull(): Long?
flatMapIndexedTo
Appends all elements yielded from results of transform function being invoked on each element and its index in the original array, to the given destination.
fun <R, C : MutableCollection<in R>> LongArray.flatMapIndexedTo(
destination: C,
transform: (index: Int, Long) -> Iterable<R>
): C
flatMapTo
Appends all elements yielded from results of transform function being invoked on each element of original array, to the given destination.
fun <R, C : MutableCollection<in R>> LongArray.flatMapTo(
destination: C,
transform: (Long) -> Iterable<R>
): C
getOrElse
Returns an element at the given index or the result of calling the defaultValue function if the index is out of bounds of this array.
fun LongArray.getOrElse(
index: Int,
defaultValue: (Int) -> Long
): Long
groupBy
Groups elements of the original array by the key returned by the given keySelector function applied to each element and returns a map where each group key is associated with a list of corresponding elements.
Groups values returned by the valueTransform function applied to each element of the original array by the key returned by the given keySelector function applied to the element and returns a map where each group key is associated with a list of corresponding values.
groupByTo
Groups elements of the original array by the key returned by the given keySelector function applied to each element and puts to the destination map each group key associated with a list of corresponding elements.
fun <K, M : MutableMap<in K, MutableList<Long>>> LongArray.groupByTo(
destination: M,
keySelector: (Long) -> K
): M
Groups values returned by the valueTransform function applied to each element of the original array by the key returned by the given keySelector function applied to the element and puts to the destination map each group key associated with a list of corresponding values.
fun <K, V, M : MutableMap<in K, MutableList<V>>> LongArray.groupByTo(
destination: M,
keySelector: (Long) -> K,
valueTransform: (Long) -> V
): M
isNotEmpty
Returns true
if the array is not empty.
fun LongArray.isNotEmpty(): Boolean
joinTo
Appends the string from all the elements separated using separator and using the given prefix and postfix if supplied.
fun <A : Appendable> LongArray.joinTo(
buffer: A,
separator: CharSequence = ", ",
prefix: CharSequence = "",
postfix: CharSequence = "",
limit: Int = -1,
truncated: CharSequence = "...",
transform: ((Long) -> CharSequence)? = null
): A
joinToString
Creates a string from all the elements separated using separator and using the given prefix and postfix if supplied.
fun LongArray.joinToString(
separator: CharSequence = ", ",
prefix: CharSequence = "",
postfix: CharSequence = "",
limit: Int = -1,
truncated: CharSequence = "...",
transform: ((Long) -> CharSequence)? = null
): String
lastOrNull
Returns the last element, or null
if the array is empty.
fun LongArray.lastOrNull(): Long?
mapIndexedTo
Applies the given transform function to each element and its index in the original array and appends the results to the given destination.
fun <R, C : MutableCollection<in R>> LongArray.mapIndexedTo(
destination: C,
transform: (index: Int, Long) -> R
): C
mapTo
Applies the given transform function to each element of the original array and appends the results to the given destination.
fun <R, C : MutableCollection<in R>> LongArray.mapTo(
destination: C,
transform: (Long) -> R
): C
maxByOrNull
Returns the first element yielding the largest value of the given function or null
if there are no elements.
fun <R : Comparable<R>> LongArray.maxByOrNull(
selector: (Long) -> R
): Long?
maxOf
Returns the largest value among all values produced by selector function applied to each element in the array.
fun <R : Comparable<R>> any_array<R>.maxOf(
selector: (Long) -> R
): R
maxOfOrNull
Returns the largest value among all values produced by selector function
applied to each element in the array or null
if there are no elements.
fun <R : Comparable<R>> any_array<R>.maxOfOrNull(
selector: (Long) -> R
): R?
maxOfWith
Returns the largest value according to the provided comparator among all values produced by selector function applied to each element in the array.
fun <R> LongArray.maxOfWith(
comparator: Comparator<in R>,
selector: (Long) -> R
): R
maxOfWithOrNull
Returns the largest value according to the provided comparator
among all values produced by selector function applied to each element in the array or null
if there are no elements.
fun <R> LongArray.maxOfWithOrNull(
comparator: Comparator<in R>,
selector: (Long) -> R
): R?
maxOrNull
Returns the largest element or null
if there are no elements.
fun LongArray.maxOrNull(): Long?
maxWith
Returns the first element having the largest value according to the provided comparator.
fun LongArray.maxWith(comparator: Comparator<in Long>): Long
fun LongArray.maxWith(comparator: Comparator<in Long>): Long?
maxWithOrNull
Returns the first element having the largest value according to the provided comparator or null
if there are no elements.
fun LongArray.maxWithOrNull(
comparator: Comparator<in Long>
): Long?
minByOrNull
Returns the first element yielding the smallest value of the given function or null
if there are no elements.
fun <R : Comparable<R>> LongArray.minByOrNull(
selector: (Long) -> R
): Long?
minOf
Returns the smallest value among all values produced by selector function applied to each element in the array.
fun <R : Comparable<R>> any_array<R>.minOf(
selector: (Long) -> R
): R
minOfOrNull
Returns the smallest value among all values produced by selector function
applied to each element in the array or null
if there are no elements.
fun <R : Comparable<R>> any_array<R>.minOfOrNull(
selector: (Long) -> R
): R?
minOfWith
Returns the smallest value according to the provided comparator among all values produced by selector function applied to each element in the array.
fun <R> LongArray.minOfWith(
comparator: Comparator<in R>,
selector: (Long) -> R
): R
minOfWithOrNull
Returns the smallest value according to the provided comparator
among all values produced by selector function applied to each element in the array or null
if there are no elements.
fun <R> LongArray.minOfWithOrNull(
comparator: Comparator<in R>,
selector: (Long) -> R
): R?
minOrNull
Returns the smallest element or null
if there are no elements.
fun LongArray.minOrNull(): Long?
minWith
Returns the first element having the smallest value according to the provided comparator.
fun LongArray.minWith(comparator: Comparator<in Long>): Long
fun LongArray.minWith(comparator: Comparator<in Long>): Long?
minWithOrNull
Returns the first element having the smallest value according to the provided comparator or null
if there are no elements.
fun LongArray.minWithOrNull(
comparator: Comparator<in Long>
): Long?
randomOrNull
Returns a random element from this array, or null
if this array is empty.
fun LongArray.randomOrNull(): Long?
refTo
fun LongArray.refTo(index: Int): CValuesRef<LongVar>
reverse
Reverses elements in the array in-place.
fun LongArray.reverse()
Reverses elements of the array in the specified range in-place.
fun LongArray.reverse(fromIndex: Int, toIndex: Int)
runningFoldIndexed
runningReduceIndexed
Returns a list containing successive accumulation values generated by applying operation from left to right to each element, its index in the original array and current accumulator value that starts with the first element of this array.
scanIndexed
single
Returns the single element, or throws an exception if the array is empty or has more than one element.
fun LongArray.single(): Long
singleOrNull
Returns single element, or null
if the array is empty or has more than one element.
fun LongArray.singleOrNull(): Long?
sliceArray
Returns an array containing elements of this array at specified indices.
fun LongArray.sliceArray(indices: Collection<Int>): LongArray
sort
Sorts the array in-place according to the order specified by the given comparison function.
fun LongArray.sort(comparison: (a: Long, b: Long) -> Int)
sortDescending
Sorts elements in the array in-place descending according to their natural sort order.
fun LongArray.sortDescending()
Sorts elements of the array in the specified range in-place. The elements are sorted descending according to their natural sort order.
fun LongArray.sortDescending(fromIndex: Int, toIndex: Int)
sortedBy
Returns a list of all elements sorted according to natural sort order of the value returned by specified selector function.
fun <R : Comparable<R>> LongArray.sortedBy(
selector: (Long) -> R?
): List<Long>
sortedByDescending
Returns a list of all elements sorted descending according to natural sort order of the value returned by specified selector function.
fun <R : Comparable<R>> LongArray.sortedByDescending(
selector: (Long) -> R?
): List<Long>
sortedWith
Returns a list of all elements sorted according to the specified comparator.
fun LongArray.sortedWith(
comparator: Comparator<in Long>
): List<Long>
sumOf
Returns the sum of all values produced by selector function applied to each element in the array.
fun LongArray.sumOf(selector: (Long) -> Double): Double
fun LongArray.sumOf(selector: (Long) -> Int): Int
fun LongArray.sumOf(selector: (Long) -> Long): Long
fun LongArray.sumOf(
selector: (Long) -> BigDecimal
): BigDecimal
fun LongArray.sumOf(
selector: (Long) -> BigInteger
): BigInteger
toCollection
Appends all elements to the given destination collection.
fun <C : MutableCollection<in Long>> LongArray.toCollection(
destination: C
): C
toMutableList
Returns a new MutableList filled with all elements of this array.
fun LongArray.toMutableList(): MutableList<Long>
toMutableSet
Returns a new MutableSet containing all distinct elements from the given array.
fun LongArray.toMutableSet(): MutableSet<Long>
toULongArray
Returns an array of type ULongArray, which is a copy of this array where each element is an unsigned reinterpretation of the corresponding element of this array.
fun LongArray.toULongArray(): ULongArray
withIndex
Returns a lazy Iterable that wraps each element of the original array into an IndexedValue containing the index of that element and the element itself.
fun LongArray.withIndex(): Iterable<IndexedValue<Long>>
zip
Returns a list of pairs built from the elements of this
array and the other array with the same index.
The returned list has length of the shortest collection.
Returns a list of values built from the elements of this
array and the other array with the same index
using the provided transform function applied to each pair of elements.
The returned list has length of the shortest collection.
Returns a list of pairs built from the elements of this
collection and other array with the same index.
The returned list has length of the shortest collection.
Returns a list of values built from the elements of this
array and the other collection with the same index
using the provided transform function applied to each pair of elements.
The returned list has length of the shortest collection.