Update a struct field
This example shows how to update a struct field.
# Define a struct for this example
defmodule User do
defstruct email: nil
end
%User{email: "[email protected]"} = struct(%User{}, email: "[email protected]")
# Structs are based on maps
# so map update methods and syntax are valid
%User{email: "[email protected]"} = %{ %User{} | email: "[email protected]" }
%User{email: "[email protected]"} = Map.put(%User{}, :email, "[email protected]")
Documentation: