[Proposal] Introduce `last` and `init` functions to Kernel

58 views
Skip to first unread message

Weslei Juan Novaes Pereira

unread,
Mar 24, 2022, 9:24:24 AM3/24/22
to elixir-lang-core
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]

eksperimental

unread,
Mar 24, 2022, 7:50:46 PM3/24/22
to elixir-l...@googlegroups.com
We already have List.last/1-2

José Valim

unread,
Mar 24, 2022, 10:48:42 PM3/24/22
to elixir-l...@googlegroups.com
The only reason why hd and tl are in Kernel is because they are allowed in guards. Currently there are no plans of adding more functions like them in Kernel.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/623d03d3.1c69fb81.7956b.42a4SMTPIN_ADDED_MISSING%40gmr-mx.google.com.
Reply all
Reply to author
Forward
0 new messages