@@ -80,19 +80,8 @@ fn decode_bit_array(a: Dynamic) -> Result(BitArray, DecodeErrors)
80
80
/// // -> Error([DecodeError(expected: "String", found: "Int", path: [])])
81
81
/// ```
82
82
///
83
- pub fn string ( from data : Dynamic ) -> Result ( String , DecodeErrors ) {
84
- decode_string ( data )
85
- }
86
-
87
- fn map_errors (
88
- result : Result ( a, DecodeErrors ) ,
89
- f : fn ( DecodeError ) -> DecodeError ,
90
- ) -> Result ( a, DecodeErrors ) {
91
- result . map_error ( result , list . map ( _, f ) )
92
- }
93
-
94
83
@ external ( javascript , "../gleam_stdlib.mjs" , "decode_string" )
95
- fn decode_string ( data : Dynamic ) -> Result ( String , DecodeErrors ) {
84
+ pub fn string ( from data : Dynamic ) -> Result ( String , DecodeErrors ) {
96
85
bit_array ( data )
97
86
|> map_errors ( put_expected ( _, "String" ) )
98
87
|> result . try ( fn ( raw ) {
@@ -104,6 +93,13 @@ fn decode_string(data: Dynamic) -> Result(String, DecodeErrors) {
104
93
} )
105
94
}
106
95
96
+ fn map_errors (
97
+ result : Result ( a, DecodeErrors ) ,
98
+ f : fn ( DecodeError ) -> DecodeError ,
99
+ ) -> Result ( a, DecodeErrors ) {
100
+ result . map_error ( result , list . map ( _, f ) )
101
+ }
102
+
107
103
fn put_expected ( error : DecodeError , expected : String ) -> DecodeError {
108
104
DecodeError ( .. error , expected : expected )
109
105
}
0 commit comments