query
On this page

last

lib.lists.last

Docs pulled from | This Revision | 10 minutes ago


Return the last element of a list.

This function throws an error if the list is empty.

Inputs

list

1. Function argument

Type

last :: [a] -> a

Examples

lib.lists.last usage example

last [ 1 2 3 ]
=> 3

Noogle detected

Aliases

Implementation

The following is the current implementation of this function.

last =
    list:
    assert lib.assertMsg (list != [ ]) "lists.last: list must not be empty!";
    elemAt list (length list - 1);