aboutsummaryrefslogtreecommitdiff
path: root/src/gleam_stdlib.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/gleam_stdlib.js')
-rw-r--r--src/gleam_stdlib.js13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/gleam_stdlib.js b/src/gleam_stdlib.js
index b7173c2..158a571 100644
--- a/src/gleam_stdlib.js
+++ b/src/gleam_stdlib.js
@@ -556,7 +556,14 @@ export function decode_option(data, decoder) {
}
export function decode_field(value, name) {
- return name in value
- ? new Ok(value[name])
- : decoder_error(`Value with field ${inspect(name)}`, value);
+ let error = () => decoder_error(`Value with field ${inspect(name)}`, value);
+ if (value instanceof Map) {
+ let entry = value.get(name);
+ return entry.isOk() ? entry : error();
+ }
+ try {
+ return name in value ? new Ok(value[name]) : error();
+ } catch {
+ return error();
+ }
}