:: [a] -> Int -> Maybe a -package:rio

List index (subscript) operator, starting from 0. Returns Nothing if the index is out of bounds This is the total variant of the partial !! operator. WARNING: This function takes linear time in the index.

Examples

>>> ['a', 'b', 'c'] !? 0
Just 'a'
>>> ['a', 'b', 'c'] !? 2
Just 'c'
>>> ['a', 'b', 'c'] !? 3
Nothing
>>> ['a', 'b', 'c'] !? (-1)
Nothing
List index (subscript) operator, starting from 0. Returns Nothing if the index is out of bounds
>>> ['a', 'b', 'c'] !? 0
Just 'a'

>>> ['a', 'b', 'c'] !? 2
Just 'c'

>>> ['a', 'b', 'c'] !? 3
Nothing

>>> ['a', 'b', 'c'] !? (-1)
Nothing
This is the total variant of the partial !! operator. WARNING: This function takes linear time in the index.
Safer version of !!, returns a Maybe. Get element from list using index value starting from `0`.
>>> [] !!? 0
Nothing
>>> ["a", "b", "c"] !!? 3
Nothing
>>> [1, 2, 3] !!? (-1)
Nothing
>>> ["a", "b", "c"] !!? 2
Just "c"
Lookup function (safe). O(min n index).
Safe version of (!!).
A (!!) that fails using mzero
!!? with its arguments flipped. Get element from list using index value starting from `0`.
>>> maybeAt 0 []
Nothing
>>> maybeAt 3 ["a", "b", "c"]
Nothing
>>> maybeAt (-1) [1, 2, 3]
Nothing
>>> maybeAt 2 ["a", "b", "c"]
Just "c"
Deprecated: Use XMonad.Prelude.(!?) instead.
Safer version of !! -
>>> fromReverseListN 3 [1,2,3] :: Data.Vector.Vector Int
[3,2,1]