last -package:foldl
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/c) Returns the last character of a
Text, which must
be non-empty. This is a partial function, consider using
unsnoc
instead.
Last element of the
Bundle or error if empty
Last element of the
Bundle or error if empty
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
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.