Programming Phoenix LiveView: assign_new (page 248)

The book contains this code

def assign_age_group_filter(%{assigns: %{age_group_filter: age_group_filter}} = socket) do
  assign(socket, :age_group_filter, age_group_filter)
end
def assign_age_group_filter(socket) do
  assign(socket, :age_group_filter, "all")
end

but this can also be solved using assign_new/3 and it might be an opportunity to teach another use case for it besides the one related to %Plug.Conn{} that you’ve already covered.

def assign_age_group_filter(socket) do
  assign_new(socket, :age_group_filter, fn -> "all" end)
end