KT-20357 Add samples for elementAt

This commit is contained in:
Takayuki Matsubara
2018-08-30 20:20:31 +09:00
committed by Ilya Gorbunov
parent 40b3514a47
commit ad9b700ec4
6 changed files with 39 additions and 0 deletions
@@ -443,6 +443,8 @@ public operator fun CharArray.contains(element: Char): Boolean {
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Usage.elementAt
*/
@kotlin.internal.InlineOnly
public inline fun <T> Array<out T>.elementAt(index: Int): T {
@@ -451,6 +453,8 @@ public inline fun <T> Array<out T>.elementAt(index: Int): T {
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Usage.elementAt
*/
@kotlin.internal.InlineOnly
public inline fun ByteArray.elementAt(index: Int): Byte {
@@ -459,6 +463,8 @@ public inline fun ByteArray.elementAt(index: Int): Byte {
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Usage.elementAt
*/
@kotlin.internal.InlineOnly
public inline fun ShortArray.elementAt(index: Int): Short {
@@ -467,6 +473,8 @@ public inline fun ShortArray.elementAt(index: Int): Short {
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Usage.elementAt
*/
@kotlin.internal.InlineOnly
public inline fun IntArray.elementAt(index: Int): Int {
@@ -475,6 +483,8 @@ public inline fun IntArray.elementAt(index: Int): Int {
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Usage.elementAt
*/
@kotlin.internal.InlineOnly
public inline fun LongArray.elementAt(index: Int): Long {
@@ -483,6 +493,8 @@ public inline fun LongArray.elementAt(index: Int): Long {
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Usage.elementAt
*/
@kotlin.internal.InlineOnly
public inline fun FloatArray.elementAt(index: Int): Float {
@@ -491,6 +503,8 @@ public inline fun FloatArray.elementAt(index: Int): Float {
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Usage.elementAt
*/
@kotlin.internal.InlineOnly
public inline fun DoubleArray.elementAt(index: Int): Double {
@@ -499,6 +513,8 @@ public inline fun DoubleArray.elementAt(index: Int): Double {
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Usage.elementAt
*/
@kotlin.internal.InlineOnly
public inline fun BooleanArray.elementAt(index: Int): Boolean {
@@ -507,6 +523,8 @@ public inline fun BooleanArray.elementAt(index: Int): Boolean {
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Usage.elementAt
*/
@kotlin.internal.InlineOnly
public inline fun CharArray.elementAt(index: Int): Char {
@@ -69,6 +69,8 @@ public operator fun <@kotlin.internal.OnlyInputTypes T> Iterable<T>.contains(ele
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this collection.
*
* @sample samples.collections.Collections.Usage.elementAt
*/
public fun <T> Iterable<T>.elementAt(index: Int): T {
if (this is List)
@@ -78,6 +80,8 @@ public fun <T> Iterable<T>.elementAt(index: Int): T {
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this list.
*
* @sample samples.collections.Collections.Usage.elementAt
*/
@kotlin.internal.InlineOnly
public inline fun <T> List<T>.elementAt(index: Int): T {
@@ -31,6 +31,8 @@ public operator fun <@kotlin.internal.OnlyInputTypes T> Sequence<T>.contains(ele
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this sequence.
*
* The operation is _terminal_.
*
* @sample samples.collections.Collections.Usage.elementAt
*/
public fun <T> Sequence<T>.elementAt(index: Int): T {
return elementAtOrElse(index) { throw IndexOutOfBoundsException("Sequence doesn't contain element at index $index.") }
@@ -20,6 +20,8 @@ import kotlin.random.*
/**
* Returns a character at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this char sequence.
*
* @sample samples.collections.Collections.Usage.elementAt
*/
@kotlin.internal.InlineOnly
public inline fun CharSequence.elementAt(index: Int): Char {