last -package:bytestring

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) 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.
O(1) Last element.
Last element of the Bundle or error if empty
Last element of the Bundle or error if empty
O(1) Last element.
O(1) Last element.
O(1) Last element.
O(1) Last element.
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). Extracts the last element of a NonEmpty list. Actual type of this function is the following:
last :: NonEmpty a -> a
but it was given a more complex type to provide friendlier compile time errors.
>>> last ('a' :| "bcde")
'e'

>>> last [0..5 :: Int]
...
... 'last' works with 'NonEmpty', not ordinary lists.
Possible fix:
Replace: [Int]
With:    NonEmpty Int
...
However, you can use 'last' with the ordinary lists.
Apply 'viaNonEmpty' function from relude:
viaNonEmpty last (yourList)
Note, that this will return 'Maybe Int'
therefore it is a safe function unlike 'last' from the standard Prelude
...

>>> last (Just 'a')
...
... 'last' works with 'NonEmpty Char' lists
But given: Maybe Char
...
O(n/c) Extract the last element of a ByteString, which must be finite and non-empty.