building39
I’m trying to update a deeply nested map (actually, a struct) and am not having any luck. Here’s the scenario:
key2 = :"some.key"
Kernel.update_in(state.key1."some.key".key3, &Map.delete(&1, "keyval")) # seems to work fine
Kernel.update_in(state.key1.key2.key3, &Map.delete(&1, "keyval")) # fails, since key2 is a data item, not an atom.
Kernel.update_in(state.key1[key2].key3, &Map.delete(&1, "keyval")) # fails atrociously - beam uses up all available ram, then crashes.
I’m sure that I’m doing this entirely wrong - I can’t believe that this would be a bug - same behavior on 1.4.5, 1.5.1 and 1.6.0-dev.
What am I doing wrong?
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
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
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
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
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
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
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
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
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










First 6 of 6 Posts
NobbZ
Small experiment on the REPL, just use
[]consistently:bglusman
Maybe I’m misunderstanding, but I beleive/thought update_in relies on Access protocol, and Struct’s don’t implement that, only maps do… I just saw @NobbZ’s post, and I did my own simpler REPL experiment to confrm, and it seems to partly support that, but maybe he understood your issue better? But since I already finished before I saw, I’ll share:
building39
Yes, that seems to do the trick. Thanks!
peerreynders
Access.key/2
bglusman
Thanks @peerreynders hadn’t seend Access.key before, though looks used under the hood by access protocol… but I mentioned the map/struct difference because @building39 said
though to be fair I’m not totally clear whether it’s a struct-nested-in-a-struct, a struct-nested-in-a-map, or something else, but I assume each level needs the Access protocol to use the syntax he was trying to use, without your Access.key addition?
peerreynders
As stated
Accessexists to provideThe OP also contained attempts to use the static access operator which will work on structs that do not implement the
Accesscallbacks. But you are correct that the structs would have to implementAccesscallbacks if the supplied list of keys contained “regular keys”.However
get_and_update_in/3andget_in/2(and cousins) will work with non-Access structs just fine if they are provided with a list of custom functions - an approach that seems appropriate when interacting with a struct or map “in a programmatic fashion”. Now in most cases the functions generated byAccess.key/2will be sufficient but it can be instructive to DIY just to see what is going on: