title: Setting existing struct value in Elixir?
body: <p>Is it possible to have a function for setting values inside an existing struct?
  I'm talking about the idea of passing the existing struct into a function and setting that structs &quot;name&quot; value (for example)?</p>
  <p>What I have:</p>
  <p><strong>main.exs</strong></p>
  <pre class="lang-elixir prettyprint-override"><code>  Code.require_file(&quot;user.exs&quot;) # Requiring in module
  
    person1 = User.constructor(&quot;Name&quot;) # Making a new user
  
    IO.write inspect person1
  </code></pre>
  <p><strong>user.exs</strong></p>
  <pre class="lang-elixir prettyprint-override"><code>defmodule User do
    defstruct [name: &quot;&quot;]
  
    def constructor(name) do
      %User{name: name}
    end
  end
  </code></pre>
  <p>Any way to get this idea working?</p>
  <pre class="lang-elixir prettyprint-override"><code>def setName(struct, newName) do
    struct.name = newName
  end
  </code></pre>
  <p>Thanks</p>