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
...