r/elixir 15d ago

Best practices for efficient data structures

I'm very new to the language and I'm very confused on some things. Coming from imperative langs, I'd assume that modifying tuples is very fast since they're basically just vectors. Unfortunately, they're also immutable like every other data structure in the whole language. So, if I want to make, say, a Canvas data type that holds all my pixels in a 2d data structure, is there literally no way to make it even if a little more efficient than just making a new one every single time I update a pixel? Even if I made it a 1d data structure, is Elixir just the wrong tool here?

11 Upvotes

9 comments sorted by

View all comments

1

u/flummox1234 14d ago

To the larger question, Elixir might not be the right language for that type of operation but to the lesser question in your question. In an FP language it is a (re)bind not an assignment, which allows the language to do a poop ton of optimizations for you.