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

      case bootstrapped?(Enum) do
        true ->
          quote do
            def __struct__(kv) do
              {map, keys} =
                Enum.reduce(kv, {__struct__(), @enforce_keys}, fn {key, val}, {map, keys} ->
                  {Map.replace!(map, key, val), List.delete(keys, key)}
                end)
              case keys do
                [] -> map
                _  -> raise ArgumentError, "the following keys must also be given when building " <>
                                           "struct #{inspect __MODULE__}: #{inspect keys}"
              end
            end
          end
        false ->

  """
  @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

