Here's a revised version with corrected grammar and clarity:
Kernel.hd/1 and Kernel.tl/1 raise an ArgumentError when given an empty list
([]). In my humble opinion, it would be beneficial to have safe versions of
these functions, ideally following Elixir's naming convention: hd! and tl!
for
I don’t think we should change semantics of hd/1 as it comes from Erlang and
can be used in guards.
Fortunately we have `List.first([])` and `Enum.drop([], 1)` as “safe"
replacements.
> On 12 Dec 2023, at 13:19, waiting-for-dev wrote:
>
> Kernel.hd/1 and Kernel.tl/1 raise an ArgumentError
Kernel.hd/1 and Kernel.tl/1 raise an ArgumentError when given an empty list
([]). In my humble opinion, it would be beneficial to have safe versions of
these functions, ideally following Elixir's naming convention: hd! and tl!
for the raising variants, and hd and tl for the safe ones returning
In addition to what Wojtek said and this being a breaking change, you can
pattern match on the empty list vs [head | tail] directly, without the
overhead of calling a function to just pattern match on ok/error.
--
You received this message because you are subscribed to the Google Groups