last -package:relude

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
The last element of a non-empty structure.
>>> last (1 :| [2, 3, 4])
4
Extract the last element of the stream.
O(1) Extract the last element of a ByteString, which must be finite and non-empty. An exception will be thrown in the case of an empty ByteString. This is a partial function, consider using unsnoc instead.
O(1) Extract the last element of a packed string, which must be non-empty.
O(n/c) Extract the last element of a ByteString, which must be finite and non-empty. This is a partial function, consider using unsnoc instead.
O(1) Extract the last element of a ShortByteString, which must be finite and non-empty. An exception will be thrown in the case of an empty ShortByteString. This is a partial function, consider using unsnoc instead.
O(1) Returns the last character of a Text, which must be non-empty. This is a partial function, consider using unsnoc instead.
O(n) Returns the last character of a Stream Char, which must be non-empty. Properties
last . stream = last
O(n/c) Returns the last character of a Text, which must be non-empty. This is a partial function, consider using unsnoc instead.
Retrieve the last value in the stream, if present. Subject to fusion
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.
Retrieve the last element from a Producer
Get the last element of a container or return Nothing if the container is empty
Get the last byte of a byte stream or return Nothing if the byte stream is empty
Get the last element of a non-empty container
Get the last character of a text stream or return Nothing if the text stream is empty
O(n/c) Extract the last element of a ByteString, which must be finite and non-empty.
O(1) Extract the last element of a ByteString, which must be finite and non-empty. An exception will be thrown in the case of an empty ByteString.
Extract the last element of a list, which must be finite and non-empty.
O(n/c) Returns the last character of a Text, which must be non-empty. Subject to fusion.
O(1) Returns the last character of a Text, which must be non-empty. Subject to fusion.
O(1) Last element