- Changed a `@doc` to `@moduledoc` so that the `Atom` module has a module documentation - Added examples to both `Atom.to_string/1` and `Atom.to_char_list/1`
40 lines
631 B
Elixir
40 lines
631 B
Elixir
defmodule Atom do
|
|
@moduledoc """
|
|
Convenience functions for working with atoms.
|
|
|
|
See also `Kernel.is_atom/1`.
|
|
"""
|
|
|
|
@doc """
|
|
Converts an atom to a string.
|
|
|
|
Inlined by the compiler.
|
|
|
|
## Examples
|
|
|
|
iex> Atom.to_string(:foo)
|
|
"foo"
|
|
|
|
"""
|
|
@spec to_string(atom) :: String.t
|
|
def to_string(atom) do
|
|
:erlang.atom_to_binary(atom, :utf8)
|
|
end
|
|
|
|
@doc """
|
|
Converts an atom to a char list.
|
|
|
|
Inlined by the compiler.
|
|
|
|
## Examples
|
|
|
|
iex> Atom.to_char_list(:"An atom")
|
|
'An atom'
|
|
|
|
"""
|
|
@spec to_char_list(atom) :: char_list
|
|
def to_char_list(atom) do
|
|
:erlang.atom_to_list(atom)
|
|
end
|
|
end
|