Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

well, I guess I gave a poor example, suppose you needed to destructure that bar! out of an ok tuple.

    def foo(bar!) do
      with {:ok, bar!} <- thing1(bar!),
           {:ok, bar!} <- thing2(bar!),
           {:ok, bar!} <- thing3(bar!) do
        bar!
      end
    end
Inspiration came from julia, where ! at the end of the function means "watch out, one of the parameters is gonna be mutated!"


Ah ok, I see! I didn't think of this situation. I'm pretty new to the language and only have done hobby projects so I haven't run into this specific scenario. I think here I would just use different names, even if ugly. To me the only "danger" is just in getting confused about what is what. There is otherwise no danger from a memory standpoint since Elixir is immutable. But I can appreciate your use of it here. [edited to add a missing word]




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: