             def __struct__(kv) do
               :lists.foldl(fn {key, val}, acc ->
                 Map.replace!(acc, key, val)
-              end, __struct__(), kv)
+              end, @struct, kv)
             end
           end
       end


  # We need this check only for bootstrap purposes.
  # Once Kernel is loaded and we recompile, it is a no-op.
  case :code.ensure_loaded(Kernel) do
    {:module, _} ->
      defp bootstrapped?(_), do: true

  """
  @spec struct(module | struct, Enum.t) :: struct
  def struct(struct, fields \\ []) do
    struct(struct, fields, fn
      {:__struct__, _val}, acc ->
        acc
      {key, val}, acc ->
        case acc do
          %{^key => _} -> %{acc | key => val}
          _ -> acc
        end
    end)
  end

