Files
n8n-openai-adapter/lib/binary/chars.ex
T
José Valim bf9fdbf071 Remove module String.
For 0.9 release we are going to have two different modules
Binary and CharList. Implementation specific behavior will
be added to those modules. At some point we can provide a
module named String that handles those differences.
2012-03-26 18:37:20 +02:00

36 lines
702 B
Elixir

import Elixir.Builtin, except: [to_binary: 1]
defprotocol Binary.Chars, [to_binary(thing)],
only: [BitString, List, Number, Atom, Record]
defimpl Binary.Chars, for: Atom do
def to_binary(nil) do
""
end
def to_binary(atom) do
atom_to_binary(atom, :utf8)
end
end
defimpl Binary.Chars, for: BitString do
def to_binary(thing) when is_binary(thing) do
thing
end
end
defimpl Binary.Chars, for: List do
def to_binary(thing) do
iolist_to_binary(thing)
end
end
defimpl Binary.Chars, for: Number do
def to_binary(thing) when is_integer(thing) do
list_to_binary integer_to_list(thing)
end
def to_binary(thing) do
list_to_binary float_to_list(thing)
end
end