1- import gleam/dynamic . { type Dynamic }
2- import gleam/dynamic/decode . { type DecodeError }
3-
41/// Atom is a special string-like data-type that is most commonly used for
52/// interfacing with code written in other BEAM languages such as Erlang and
63/// Elixir. It is preferable to define your own custom types to use instead of
@@ -18,29 +15,13 @@ import gleam/dynamic/decode.{type DecodeError}
1815///
1916pub type Atom
2017
21- /// An error returned when no atom is found in the virtual machine's atom table
22- /// for a given string when calling the [`from_string`](#from_string) function.
23- pub type FromStringError {
24- AtomNotLoaded
25- }
26-
27- /// Finds an existing Atom for the given String.
18+ /// Finds an existing atom for the given string.
2819///
29- /// If no atom is found in the virtual machine's atom table for the String then
20+ /// If no atom is found in the virtual machine's atom table for the string then
3021/// an error is returned.
3122///
32- /// ## Examples
33- /// ```gleam
34- /// from_string("ok")
35- /// // -> Ok(create_from_string("ok"))
36- /// ```
37- /// ```gleam
38- /// from_string("some_new_atom")
39- /// // -> Error(AtomNotLoaded)
40- /// ```
41- ///
4223@ external ( erlang , "gleam_erlang_ffi" , "atom_from_string" )
43- pub fn from_string ( a : String ) -> Result ( Atom , FromStringError )
24+ pub fn get ( a : String ) -> Result ( Atom , Nil )
4425
4526/// Creates an atom from a string, inserting a new value into the virtual
4627/// machine's atom table if an atom does not already exist for the given
@@ -52,34 +33,17 @@ pub fn from_string(a: String) -> Result(Atom, FromStringError)
5233/// virtual machine to crash!
5334///
5435@ external ( erlang , "erlang" , "binary_to_atom" )
55- pub fn create_from_string ( a : String ) -> Atom
36+ pub fn create ( a : String ) -> Atom
5637
5738/// Returns a `String` corresponding to the text representation of the given
5839/// `Atom`.
5940///
6041/// ## Examples
6142/// ```gleam
62- /// let ok_atom = create_from_string ("ok")
43+ /// let ok_atom = create ("ok")
6344/// to_string(ok_atom)
6445/// // -> "ok"
6546/// ```
6647///
6748@ external ( erlang , "erlang" , "atom_to_binary" )
6849pub fn to_string ( a : Atom ) -> String
69-
70- /// Checks to see whether a `Dynamic` value is an atom, and return the atom if
71- /// it is.
72- ///
73- /// ## Examples
74- /// ```gleam
75- /// import gleam/dynamic
76- /// from_dynamic(dynamic.from(create_from_string("hello")))
77- /// // -> Ok(create_from_string("hello"))
78- /// ```
79- /// ```gleam
80- /// from_dynamic(dynamic.from(123))
81- /// // -> Error([DecodeError(expected: "Atom", found: "Int", path: [])])
82- /// ```
83- ///
84- @ external ( erlang , "gleam_erlang_ffi" , "atom_from_dynamic" )
85- pub fn from_dynamic ( from from : Dynamic ) -> Result ( Atom , List ( DecodeError ) )
0 commit comments