to_atom_in is a small utility to safely convert string to atom from a set. It is similar to String.to_existing_atom/1
, but it also verifies that the resulting atom is one of the provided.
require TAI
TAI.to_atom_in("world", [:hello, :world])
:world
or
import TAI
to_atom_in("world", ~w(hello world)a)
:world
In case if resulting atom is not from the given list, ArgumentError is raised.
import TAI
to_atom_in("three", ~w(one two)a)
# ** (ArgumentError) The atom three is not in the [:one, :two]
to_atom_in
in Hex.