All Downloads are FREE. Search and download functionalities are using the official Maven repository.

kotlin.collections.CollectionsH.kt Maven / Gradle / Ivy

There is a newer version: 2.1.0-RC
Show newest version
/*
 * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
 * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
 */

package kotlin.collections

/**
 * Marker interface indicating that the [List] implementation supports fast indexed access.
 */
public expect interface RandomAccess

/**
 * Returns the array if it's not `null`, or an empty array otherwise.
 * @sample samples.collections.Arrays.Usage.arrayOrEmpty
 */
public expect inline fun  Array?.orEmpty(): Array

/**
 * Returns a *typed* array containing all the elements of this collection.
 *
 * Allocates an array of runtime type `T` having its size equal to the size of this collection
 * and populates the array with the elements of this collection.
 * @sample samples.collections.Collections.Collections.collectionToTypedArray
 */
public expect inline fun  Collection.toTypedArray(): Array

/**
 * Fills the list with the provided [value].
 *
 * Each element in the list gets replaced with the [value].
 */
@SinceKotlin("1.2")
public expect fun  MutableList.fill(value: T): Unit

/**
 * Randomly shuffles elements in this list.
 *
 * See: https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm
 */
@SinceKotlin("1.2")
public expect fun  MutableList.shuffle(): Unit

/**
 * Returns a new list with the elements of this collection randomly shuffled.
 */
@SinceKotlin("1.2")
public expect fun  Iterable.shuffled(): List

/**
 * Sorts elements in the list in-place according to their natural sort order.
 *
 * The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
 *
 * @sample samples.collections.Collections.Sorting.sortMutableList
 */
public expect fun > MutableList.sort(): Unit


/**
 * Sorts elements in the list in-place according to the order specified with [comparator].
 *
 * The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
 *
 * @sample samples.collections.Collections.Sorting.sortMutableListWith
 */
public expect fun  MutableList.sortWith(comparator: Comparator): Unit


// from Grouping.kt
public expect fun  Grouping.eachCount(): Map
// public expect inline fun  Grouping.eachSumOf(valueSelector: (T) -> Int): Map

internal expect fun collectionToArray(collection: Collection<*>): Array

internal expect fun  collectionToArray(collection: Collection<*>, array: Array): Array

internal expect fun  arrayOfNulls(reference: Array, size: Int): Array
internal expect fun  Map.toSingletonMapOrSelf(): Map
internal expect fun  Map.toSingletonMap(): Map
internal expect fun  Array.copyToArrayOfAny(isVarargs: Boolean): Array




© 2015 - 2024 Weber Informatics LLC | Privacy Policy