No, you can’t avoid rebinding, there’s no implicit mutable state, there are no stateful objects in functional land. Modules are not like classes, they’re just a bag of functions. Everything you do in the language will behave like that. This requires you to approach problems with a different mindset and you should not try to force OOP patterns here.
If you want to keep the state and “mutate” it over time, then you can spawn a genserver and keep the queue as it’s state. Check the elixir guide to see an example of a stateful Key-Value store.
q = Fifo.new() |> Fifo.in!(1)
# do something else
q = Fifo.in!(q, 2)
There’s no other way around it, the whole language works this way, it has nothing to do with the way the queue is implemented in erlang(it’s just a data structure).






















