GitHub avatar of almirsarajcic

Almir Sarajčić

almirsarajcic

View on GitHub
  • 168 Drops
  • 8 Comments

Replying to Dean Kinyua I took it for a spin. It catches repo related issues well. Good work

Asante 🙏

View in discussion

Danni Friedland in the Twitter reply correctly pointed out my oversight:

did you note that he iterated for days on the rust version while the elixir is a single commit?

https://x.com/DanniFriedland/status/2107131056059302375

Truth be told, the fair comparison would be in comparing numbers for the first, one-shot, versions, along with the final, fine-tuned ones.

View in discussion

Replying to Dean Kinyua Would it be advisable to store 2 Ecto Structs that are frequently needed and never updated in a persistent_term? I fetch…

Sure. That’s a good use case!
I gotta do more of that.

View in discussion

Replying to Santiago Papiernik It is possible to call IO.iodata_to_binary(rows) directly, since rows is already a valid iodata

Good catch!
In this exact scenario, that’s probably the best option.

View in discussion

Replying to Santiago Papiernik Why not get_in(user.profile.city)?

That’s fine when you know which fields you explicitly set fields which you want to traverse, but if you want to dynamically fetch a field, you get an error, e.g.

iex(17)> field = :profile
:profile
iex(18)> get_in(user[field].city)
** (UndefinedFunctionError) function User.fetch/2 is undefined (User does not implement the Access behaviour

You can use the "struct.field" syntax to access struct fields. You can also use Access.key!/1 to access struct fields dynamically inside get_in/put_in/update_in). Make sure the module name is correct and has been specified in full (or that an alias has been defined)
    User.fetch(%User{name: "Ada", profile: %Profile{city: "London", country: "UK"}}, :profile)
    (elixir 1.20.2) lib/access.ex:326: Access.get/3
    iex:18: (file)

You can do it this way:

iex(18)> get_in(user, [Access.key!(field), Access.key!(:city)])
"London"
View in discussion