KT-20357 Add samples for elementAtOrNull

This commit is contained in:
Takayuki Matsubara
2018-09-15 21:25:05 +09:00
committed by Ilya Gorbunov
parent ad9b700ec4
commit 7d5efe7f51
6 changed files with 38 additions and 0 deletions
@@ -116,6 +116,8 @@ public inline fun <T> List<T>.elementAtOrElse(index: Int, defaultValue: (Int) ->
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this collection.
*
* @sample samples.collections.Collections.Usage.elementAtOrNull
*/
public fun <T> Iterable<T>.elementAtOrNull(index: Int): T? {
if (this is List)
@@ -134,6 +136,8 @@ public fun <T> Iterable<T>.elementAtOrNull(index: Int): T? {
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this list.
*
* @sample samples.collections.Collections.Usage.elementAtOrNull
*/
@kotlin.internal.InlineOnly
public inline fun <T> List<T>.elementAtOrNull(index: Int): T? {