Skip to content

Commit f5585ad

Browse files
committed
New decode module
1 parent d50616d commit f5585ad

File tree

6 files changed

+2009
-13
lines changed

6 files changed

+2009
-13
lines changed

src/gleam/dynamic.gleam

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,8 @@ fn decode_bit_array(a: Dynamic) -> Result(BitArray, DecodeErrors)
8080
/// // -> Error([DecodeError(expected: "String", found: "Int", path: [])])
8181
/// ```
8282
///
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-
9483
@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) {
9685
bit_array(data)
9786
|> map_errors(put_expected(_, "String"))
9887
|> result.try(fn(raw) {
@@ -104,6 +93,13 @@ fn decode_string(data: Dynamic) -> Result(String, DecodeErrors) {
10493
})
10594
}
10695

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+
107103
fn put_expected(error: DecodeError, expected: String) -> DecodeError {
108104
DecodeError(..error, expected: expected)
109105
}

0 commit comments

Comments
 (0)