tsutsu

tsutsu

Why are the accessor functions in Access strict?

get_in and its related lensing macros have the “default” or “built-in” behavior (for Map keys, the only thing they support by default) of being forgiving when you attempt to navigate further from a non-existent key. For example:

iex> get_in(%{}, [:a, :b])
nil

However, none of the “accessor” functions in Access (Access.at/1, Access.elem/1, Access.all/0)—which, as far as I understand, only exist to be used in this set of lensing macros—“follow the lead” of the built-in behavior of these functions, in terms of how they handle navigating from a nil parent.

iex> get_in(%{}, [:a, Access.at(0), :b])
** (RuntimeError) Access.at/1 expected a list, got: nil

Is there a reason for this difference?

Is it necessary—e.g. can the modifying lens macros (put_in et al) not work with non-strict accessors for other types, the way they work with non-strict accesses of map keys?

Or could there be safe/non-strict variants of these accessor-fun-returning functions that do work this way? (I’ve written such variants myself, but only for get_in.)

Where Next?

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2976 91332 914
New
byu
@chrismccord : I just saw the Extract AGENTS.md from Phoenix.new into phx.new generator commit to the phoenix project. My initial shotgu...
New
arcanemachine
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
AstonJ
Just a general thread to post chat/news/info relating to AI/ML stuff that may be relevant for Nx now or in the future. Got anything to sh...
New
type1fool
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
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
matt-savvy
Is there a word for the ~> symbol used in Version strings? Do you also just call it a Squiggle Arrow™ ?!
New

Other Trending Topics Top

JesseHerrick
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
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
ausimian
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
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
zachdaniel
Introducing AshStorage! Attachment and file management that slots directly into your resources :smiling_face_with_sunglasses: I had hope...
New

We're in Beta

About us Mission Statement