1- import gleam/bit_string . { BitString }
1+ import gleam/bit_string . { BitString } as bit_string_mod
22import gleam/list as list_mod
33import gleam/atom
44import gleam/map . { Map }
@@ -27,8 +27,19 @@ pub external fn from(a) -> Dynamic =
2727pub external fn unsafe_coerce ( Dynamic ) -> a =
2828 "gleam_stdlib" "identity"
2929
30- external fn erl_string ( from : Dynamic ) -> Result ( BitString , String ) =
31- "gleam_stdlib" "decode_string"
30+ /// Check to see whether a Dynamic value is a bit_string, and return the bit_string if
31+ /// it is.
32+ ///
33+ /// ## Examples
34+ ///
35+ /// > bit_string(from("Hello")) == bit_string.from_string("Hello")
36+ /// True
37+ ///
38+ /// > bit_string(from(123))
39+ /// Error("Expected a BitString, got `123`")
40+ ///
41+ pub external fn bit_string ( from : Dynamic ) -> Result ( BitString , String ) =
42+ "gleam_stdlib" "decode_bit_string"
3243
3344/// Check to see whether a Dynamic value is a string, and return the string if
3445/// it is.
@@ -42,31 +53,17 @@ external fn erl_string(from: Dynamic) -> Result(BitString, String) =
4253/// Error("Expected a String, got `123`")
4354///
4455pub fn string ( from : Dynamic ) -> Result ( String , String ) {
45- erl_string ( from )
56+ bit_string ( from )
4657 |> result . then (
4758 fn ( raw ) {
48- case bit_string . to_string ( raw ) {
59+ case bit_string_mod . to_string ( raw ) {
4960 Ok ( string ) -> Ok ( string )
5061 Error ( Nil ) -> Error ( "Expected a string, got a bit_string" )
5162 }
5263 } ,
5364 )
5465}
5566
56- /// Check to see whether a Dynamic value is a bit_string, and return the bit_string if
57- /// it is.
58- ///
59- /// ## Examples
60- ///
61- /// > bit_string(from("Hello")) == bit_string.from_string("Hello")
62- /// True
63- ///
64- /// > bit_string(from(123))
65- /// Error("Expected a BitString, got `123`")
66- ///
67- pub external fn bit_string ( from : Dynamic ) -> Result ( BitString , String ) =
68- "gleam_stdlib" "decode_bit_string"
69-
7067/// Check to see whether a Dynamic value is an int, and return the int if it
7168/// is.
7269///
0 commit comments