1
- import gleam/bit_string . { BitString }
1
+ import gleam/bit_string . { BitString } as bit_string_mod
2
2
import gleam/list as list_mod
3
3
import gleam/atom
4
4
import gleam/map . { Map }
@@ -27,8 +27,19 @@ pub external fn from(a) -> Dynamic =
27
27
pub external fn unsafe_coerce ( Dynamic ) -> a =
28
28
"gleam_stdlib" "identity"
29
29
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"
32
43
33
44
/// Check to see whether a Dynamic value is a string, and return the string if
34
45
/// it is.
@@ -42,31 +53,17 @@ external fn erl_string(from: Dynamic) -> Result(BitString, String) =
42
53
/// Error("Expected a String, got `123`")
43
54
///
44
55
pub fn string ( from : Dynamic ) -> Result ( String , String ) {
45
- erl_string ( from )
56
+ bit_string ( from )
46
57
|> result . then (
47
58
fn ( raw ) {
48
- case bit_string . to_string ( raw ) {
59
+ case bit_string_mod . to_string ( raw ) {
49
60
Ok ( string ) -> Ok ( string )
50
61
Error ( Nil ) -> Error ( "Expected a string, got a bit_string" )
51
62
}
52
63
} ,
53
64
)
54
65
}
55
66
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
-
70
67
/// Check to see whether a Dynamic value is an int, and return the int if it
71
68
/// is.
72
69
///
0 commit comments