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 the raising variants, and hd and tl for the safe ones returning {:ok, 
term} or {:error, :empty_list}. I understand that this may not be a problem 
for writing expressive code, as we can always pattern match on lists 
instead of using these two functions. However, I believe it could be a 
potential issue for newcomers. Of course, the elephant in the room here is 
backward compatibility, but perhaps that could be considered for a major 
release?

For what it's worth, the same issue exists in the Haskell ecosystem, where 
the head and tail functions defined in the Prelude also raise errors on 
empty lists. This has been a persistent annoyance for the community, and 
many alternative Preludes ship with functions returning Maybe a values to 
address this. While the official Prelude in Haskell has never changed for 
backward compatibility reasons, in Haskell, you have the option to not 
import it, but that's not an option in Elixir.

Any ideas? I'm happy to hear everyone's thoughts on this. Thanks in advance 
for your feedback.

-- 
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-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/342ebfb0-072d-438b-96d7-bb2886223a99n%40googlegroups.com.

Reply via email to