Hi all,
I ran across a case where I wanted to try to convert a string to an
existing atom or create a new one if there is no such atom. So I hacked
this together:
defmodule String.Extensions do
def to_existing_or_new_atom(s) when is_binary(s) do
a =
try do
String.to_existing_atom(s)
rescue
ArgumentError -> String.to_atom(s)
end
end
end
I find it hard to believe that I'm the first person to come across this
issue and so I'm inclined to think there's a good reason that this isn't
already part of the string module. I'm guessing that probably we want to
see if we try to convert to an existing atom and it's not there.
So:
a.) Would this be a welcome PR?
b.) Assuming it wouldn't am I correct in assuming we want the exception
thrown if we try to convert to a non-existent atom? As I say this seems so
obvious I find it very hard to believe I'm the first one to run across
this. I did a quick search but didn't really turn anything up on this.
--
You received this message because you are subscribed to the Google Groups
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elixir-lang-core/cb21dfeb-154f-486e-941c-12e2d0bc19e4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.