Skip to content

Instantly share code, notes, and snippets.

@binarytemple-external
Last active April 18, 2017 15:16
Show Gist options
  • Save binarytemple-external/845aeba6fe26502c62e733bc1cd8e3f5 to your computer and use it in GitHub Desktop.
Save binarytemple-external/845aeba6fe26502c62e733bc1cd8e3f5 to your computer and use it in GitHub Desktop.
elixir map protocol
defimpl String.Chars, for: Map do                                                      
                                                                                       
  import Kernel, except: [to_string: 1]                                                
                                                                                       
  def to_string(m) when is_map(m) do                                                                  
    #for i <- Map.to_list(m), do: "#{to_string(elem(i,0))} -> #{to_string(elem(i,1))}"  
    "#{inspect(m)}"
  end                                                                                  
  
  #def to_string(a) when is_atom(a) do
  #  :erlang.atom_to_binary(a,:latin1)      
  #end
  
  #def to_string(x) do
  #  "#{inspect(x)}"
  #end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment