img

To boost your Elixir coding, you need to understand a few differences between these two even though they are used for the same purpose.

hd ( vs ) List.first [ diff…]

We all knew that hd & List.first are used to pick out the first element in a list . But, why two functions for the same purpose?
However, they differ slightly in dealing with the empty list [] and in guard tests.

Differences

  1. on Empty listsThe function hd on empty list [] results in Argument Error
    The function List.first on empty list [] results in nil
  2. on guard testsThe function hd is allowed in guard tests. In lined by the compiler.
    The function List.firstis** not allowed in **guard tests.

Lets check this in live

Hope you got some idea and understood where and when to use them.

Guys, I love to hear more on this through reply which would help the programmers to write the better code.

Sharing is Caring !!

Thanks Giving
Hey guys!
Thanks for the support you have shown in reading and clapping the previous parts of this category.

If you want to read more on this kinda things, check below.

Read all parts of Killer Elixir Tips and download README.MD file at GitHub .
Click on link All 10 Killer Elixir Tips Parts. Contribute with a ★

Happy Coding !!