We already have List.last/1-2
On Thu, 24 Mar 2022 06:24:24 -0700 (PDT)
Weslei Juan Novaes Pereira wrote:
> As Elixir has the `hd` and `tl` functions, it'd be very useful to
> have a `init` and `last` functions as well. For example:
>
> last: takes a list and returns its last element.
> iex>
As Elixir has the `hd` and `tl` functions, it'd be very useful to have a
`init` and `last` functions as well. For example:
last: takes a list and returns its last element.
iex> last [5,4,3,2,1]
1
init: takes a list and returns everything except its last element.
iex> init [5,4,3,2,1]
[5,4,3,2]