   @spec extract_type(map) :: {atom, keyword}
   defp extract_type(%{type: type} = schema),
     do: {type, schema |> Map.delete(:type) |> Map.to_list()}
-
-  @spec merge({atom, keyword}, keyword) :: {atom, keyword}
-  defp merge({type, keywords}, add), do: {type, Keyword.merge(keywords, add)}
 end


  def to_string(%Xema.Schema{} = schema, opts) do
    format = Keyword.get(opts, :format, :data)
    keywords = Keyword.get(opts, :keywords, [])
    root = Keyword.get(opts, :root, true)
    tuple = to_tuple(schema, keywords)

    do_to_string(format, tuple, root)
  end

  @spec wrap(String.t(), String.t(), String.t()) :: String.t()
  defp wrap(str, trailing, pending), do: "#{trailing}#{str}#{pending}"

  @spec to_tuple(Xema.Schema.t()) :: tuple
  defp to_tuple(%Xema.Schema{} = schema) do
    schema
    |> Map.from_struct()
    |> delete_as()
    |> delete_nils()
    |> extract_type()
  end

  @spec delete_as(map) :: map
