You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
add a extension function getOrNull(int index) on List to get element at the specified index safely. If out of bounds, return null.
It can work well with nnbd.
No current plans to treat index errors as acceptable in lists. Don't expect that to change. It's very easy to do a list.length check first, rather than have a function that silently ignores out-of-bound accesses.
For iterable, it makes more sense ... but annoyingly an operation on iterable will work for List too.
Still, I'd prefer something cleaner, not null based, like Option<T> tryElementAt(int index) that would return a recognizable non-value if index is too big. (And it'll still throw for negative indices.)
add a extension function
getOrNull(int index)
on List to get element at the specified index safely. If out of bounds, return null.It can work well with nnbd.
ref: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/get-or-null.html
The text was updated successfully, but these errors were encountered: