getOrNull

inline fun <T> Array<T>.getOrNull(indices: IntRange): Array<T>?

Returns the sub-array from the given range if exist otherwise return a null.

Example:

arrayOf(1..10).getOrNull(0..4)!! // [1, 2, 3, 4, 5]
arrayOf(1..10).getOrNull(10..14) // null

Since

1.1.0

See also

sliceArray
Array

fun ByteArray.getOrNull(indices: IntRange): ByteArray?

Returns the sub-array from the given range if exist otherwise return a null.

Example:

byteArrayOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).getOrNull(0..4)!! // [1, 2, 3, 4, 5]
byteArrayOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).getOrNull(10..14) // null

Since

1.1.0

See also

sliceArray
byteArrayOf

fun CharArray.getOrNull(indices: IntRange): CharArray?

Returns the sub-array from the given range if exist otherwise return a null.

Example:

charArrayOf('a'..'z').getOrNull(0..4)!! // ['a', 'b', 'c', 'd', 'e']
charArrayOf('a'..'c').getOrNull(10..14) // null

Since

1.1.0

See also

sliceArray

fun ShortArray.getOrNull(indices: IntRange): ShortArray?

Returns the sub-array from the given range if exist otherwise return a null.

Example:

shortArrayOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).getOrNull(0..4)!! // [1, 2, 3, 4, 5]
shortArrayOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).getOrNull(10..14) // null

Since

1.1.0

See also

sliceArray
shortArrayOf

fun IntArray.getOrNull(indices: IntRange): IntArray?

Returns the sub-array from the given range if exist otherwise return a null.

Example:

intArrayOf(1..10).getOrNull(0..4)!! // [1, 2, 3, 4, 5]
intArrayOf(1..10).getOrNull(10..14) // null

Since

1.1.0

See also

sliceArray

fun LongArray.getOrNull(indices: IntRange): LongArray?

Returns the sub-array from the given range if exist otherwise return a null.

Example:

longArrayOf(1..10L).getOrNull(0..4)!! // [1L, 2L, 3L, 4L, 5L]
longArrayOf(1..10L).getOrNull(10..14) // null

Since

1.1.0

See also

sliceArray

fun FloatArray.getOrNull(indices: IntRange): FloatArray?

Returns the sub-array from the given range if exist otherwise return a null.

Example:

floatArrayOf(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f)
.getOrNull(0..4)!! // [1.0f, 2.0f, 3.0f, 4.0f, 5.0f]
floatArrayOf(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f)
.getOrNull(10..14) // null

Since

1.1.0

See also

sliceArray
floatArrayOf

fun DoubleArray.getOrNull(indices: IntRange): DoubleArray?

Returns the sub-array from the given range if exist otherwise return a null.

Example:

doubleArrayOf(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0).getOrNull(0..4)!!
// [1.0, 2.0, 3.0, 4.0, 5.0]
doubleArrayOf(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0).getOrNull(10..14) // null

Since

1.1.0

See also

sliceArray
doubleArrayOf

fun BooleanArray.getOrNull(indices: IntRange): BooleanArray?

Returns the sub-array from the given range if exist otherwise return a null.

Example:

booleanArrayOf(true, false, true, false, true, false, true, false, true, false)
.getOrNull(0..4)!! // [true, false, true, false, true]
booleanArrayOf(true, false, true, false, true, false, true, false, true, false)
.getOrNull(10..14) // null

Since

1.1.0

See also

sliceArray
booleanArrayOf

inline fun <T> Array<T>.getOrNull(indices: IntProgression): Array<T>?

Returns the sub-array from the given progression if exist otherwise return a null.

Example:

arrayOf(1..10).getOrNull(0..9 step 2)!! // [1, 3, 5, 7, 9]
arrayOf(1..10).getOrNull(10..14 step 2) // null

Since

1.1.0

See also

sliceArray
Array

fun ByteArray.getOrNull(indices: IntProgression): ByteArray?

Returns the sub-array from the given progression if exist otherwise return a null.

Example:

byteArrayOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).getOrNull(0..9 step 2)!! // [1, 3, 5, 7, 9]
byteArrayOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).getOrNull(10..14 step 2) // null

Since

1.1.0

See also

sliceArray
byteArrayOf

fun CharArray.getOrNull(indices: IntProgression): CharArray?

Returns the sub-array from the given progression if exist otherwise return a null.

Example:

charArrayOf('a'..'z').getOrNull(0..9 step 2)!! // ['a', 'c', 'e', 'g', 'i']
charArrayOf('a'..'c').getOrNull(10..14 step 2) // null

Since

1.1.0

See also

sliceArray

fun ShortArray.getOrNull(indices: IntProgression): ShortArray?

Returns the sub-array from the given progression if exist otherwise return a null.

Example:

shortArrayOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).getOrNull(0..9 step 2)!! // [1, 3, 5, 7, 9]
shortArrayOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).getOrNull(10..14 step 2) // null

Since

1.1.0

See also

sliceArray
shortArrayOf

fun IntArray.getOrNull(indices: IntProgression): IntArray?

Returns the sub-array from the given progression if exist otherwise return a null.

Example:

intArrayOf(1..10).getOrNull(0..9 step 2)!! // [1, 3, 5, 7, 9]
intArrayOf(1..10).getOrNull(10..14 step 2) // null

Since

1.1.0

See also

sliceArray

fun LongArray.getOrNull(indices: IntProgression): LongArray?

Returns the sub-array from the given progression if exist otherwise return a null.

Example:

longArrayOf(1..10L).getOrNull(0..9 step 2)!! // [1L, 3L, 5L, 7L, 9L]
longArrayOf(1..10L).getOrNull(10..14 step 2) // null

Since

1.1.0

See also

sliceArray

fun FloatArray.getOrNull(indices: IntProgression): FloatArray?

Returns the sub-array from the given progression if exist otherwise return a null.

Example:

floatArrayOf(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f)
.getOrNull(0..9 step 2)!! // [1.0f, 3.0f, 5.0f, 7.0f, 9.0f]
floatArrayOf(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f)
.getOrNull(10..14 step 2) // null

Since

1.1.0

See also

sliceArray
floatArrayOf

fun DoubleArray.getOrNull(indices: IntProgression): DoubleArray?

Returns the sub-array from the given progression if exist otherwise return a null.

Example:

doubleArrayOf(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0)
.getOrNull(0..9 step 2)!! // [1.0, 3.0, 5.0, 7.0, 9.0]
doubleArrayOf(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0)
.getOrNull(10..14 step 2) // null

Since

1.1.0

See also

sliceArray
doubleArrayOf

fun BooleanArray.getOrNull(indices: IntProgression): BooleanArray?

Returns the sub-array from the given progression if exist otherwise return a null.

Example:

booleanArrayOf(true, false, true, false, true, false, true, false, true, false)
.getOrNull(0..9 step 2)!! // [true, true, true, true, true]
booleanArrayOf(true, false, true, false, true, false, true, false, true, false)
.getOrNull(10..14 step 2) // null

Since

1.1.0

See also

sliceArray
booleanArrayOf

inline fun <T> Iterable<T>.getOrNull(indices: IntRange): List<T>?

Returns the sub-listOf from the given range if exist otherwise return a null.

Example:

listOf(1..10).getOrNull(0..4)!! // [1, 2, 3, 4, 5]
listOf(1..10).getOrNull(10..14) // null

Since

1.1.0

See also

slice

inline fun <T> Iterable<T>.getOrNull(indices: IntProgression): List<T>?

Returns the sub-list from the given progression if exist otherwise return a null.

Example:

listOf(1..10).getOrNull(0..9 step 2)!! // [1, 3, 5, 7, 9]
listOf(1..10).getOrNull(10..14 step 2) // null

Since

1.1.0

See also

slice