if Within Bound
inline fun <E, R> List<E>.ifWithinBound(index: Int, thenBlock: () -> R, elseBlock: () -> R): R(source)
inline fun <E, R> Array<E>.ifWithinBound(index: Int, thenBlock: () -> R, elseBlock: () -> R): R(source)
Checks if the given index is within the bound of this List (index<List.size) and correspondingly executes the thenBlock or the elseBlock.
Use getOrElse in case you want to retrieve the element at position index or a default value. This function is meant for other things such as check if upper bound of range is within bound and return a sublist or return an empty list etc.