minhajuddin
Using List.first instead of Enum.at(0)
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people use Enum.at(0)? List.first seems like the simpler of the two.
Trending in Questions
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated!
To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead.
Sta...
New
Hello !
We want new/edit form pages to POST/PUT to their own URL rather than the resources REST defaults (post /things, put /things/:id)...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New
Other Trending Topics
SuperAPI will be hosting the Melbourne Elixir meetup this Thursday, August 6th. The event will be held at Level 2, 525 Collins St (Rialto...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #performance
- #security










First Post!
alexgaribay
The docs for the
Listmodule states it works only on lists whereas theEnummodule works on anything that implements theEnumerableprotocol. Additionally, theListmodule docs recommends using theEnummodule.This comes directly from the
Listdocs:I’d probably go with using
Enumin general. I have never found myself reaching for an API available inListin the past year of my Elixir development.Most Liked
benwilson512
FWIW I literally never use
Enum.at. Lists are the only thing I end up using on a regularly basis where “first” actually means something. That is, I’m not sure why I would ever callEnum.at(0)on a map. Given that looking at a list,List.firstis just more semantically clear.rkma
The difference is that, for an empty list,
List.first/1andEnum.at/2will returnnilandhdand pattern matching will raise an error.benwilson512
There’s a big difference between
hdandList.firsthowever.[] |> hdblows up.[] |> List.firstisnil. I almost never usehdbecause I can generally just pattern match when I expect there will be one thing.List.firstis handy when I either want the first thing or nil if there isn’t any.Last Post!
dkuku
only Enum.at(0) works with Streams