:: [t] -> t -package:protolude
Extract the last element of a list, which must be finite
and non-empty.
WARNING: This function is partial. Consider using
unsnoc
instead.
Examples
>>> last [1, 2, 3]
3
>>> last [1..]
* Hangs forever *
>>> last []
*** Exception: Prelude.last: empty list
Identical to
head, namely that fails on an empty list. Useful
to avoid the
x-partial warning introduced in GHC 9.8.
headErr [] = error "Prelude.head: empty list"
headErr [1,2,3] = 1
Extract the first element of a list, which must be
non-empty.
>>> head [1, 2, 3]
1
>>> head [1..]
1
>>> head []
*** Exception: Prelude.head: empty list
WARNING: This function is partial. You can use case-matching,
uncons or
listToMaybe instead.
Extract the last element of a list, which must be finite
and non-empty.
>>> last [1, 2, 3]
3
>>> last [1..]
* Hangs forever *
>>> last []
*** Exception: Prelude.last: empty list
WARNING: This function is partial. You can use
reverse with
case-matching,
uncons or
listToMaybe instead.
Utility function to go from a singleton list to it's element.
Wether or not the argument is a singleton list is only checked in
debug builds.
Extract the first element of a list, which must be
non-empty.
>>> head [1, 2, 3]
1
>>> head [1..]
1
>>> head []
*** Exception: Prelude.head: empty list
Extract the first element of a list, which must be
non-empty.
Examples
>>> head [1, 2, 3]
1
>>> head [1..]
1
>>> head []
*** Exception: Prelude.head: empty list
Extract the first element of a list, which must be
non-empty.
Extract the last element of a list, which must be finite
and non-empty.
Extract the last element of a list, which must be finite
and non-empty.
>>> last [1, 2, 3]
3
>>> last [1..]
* Hangs forever *
>>> last []
*** Exception: Prelude.last: empty list
O(1) First element, without checking if the vector is empty.