aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md4
-rw-r--r--src/gleam/dynamic.gleam12
-rw-r--r--test/gleam/dynamic_test.gleam8
3 files changed, 18 insertions, 6 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 234806a..a4e13de 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,8 +15,8 @@
the field to be specified.
- The `dynamic.DecodeError` now has a `path` field.
- The decoder functions of the `dynamic` module now return multiple errors.
-- The `dynamic.element` and `dynamic.tuple*` functions are now partially
- applied.
+- The `dynamic.any`, `dynamic.element` and `dynamic.tuple*` functions are now
+ partially applied.
- The `dynamic` module gains the `decode2` function.
- The `int` module gains the `digits` and `undigits` functions.
diff --git a/src/gleam/dynamic.gleam b/src/gleam/dynamic.gleam
index be48206..4571b20 100644
--- a/src/gleam/dynamic.gleam
+++ b/src/gleam/dynamic.gleam
@@ -905,10 +905,14 @@ pub fn decode2(
fn(value) {
case decode1(value), decode2(value) {
Ok(a), Ok(b) -> Ok(constructor(a, b))
- a, b ->
- tuple_errors(a, "0")
- |> list.append(tuple_errors(b, "1"))
- |> Error
+ a, b -> Error(list.flatten([all_errors(a), all_errors(b)]))
}
}
}
+
+fn all_errors(result: Result(a, List(DecodeError))) -> List(DecodeError) {
+ case result {
+ Ok(_) -> []
+ Error(errors) -> errors
+ }
+}
diff --git a/test/gleam/dynamic_test.gleam b/test/gleam/dynamic_test.gleam
index d35c3d0..1bfc255 100644
--- a/test/gleam/dynamic_test.gleam
+++ b/test/gleam/dynamic_test.gleam
@@ -802,4 +802,12 @@ pub fn decode2_test() {
|> dynamic.from
|> decoder
|> should.equal(Ok(Two(1, 2.0)))
+
+ #(1.3, 2)
+ |> dynamic.from
+ |> decoder
+ |> should.equal(Error([
+ DecodeError(expected: "Int", found: "Float", path: ["0"]),
+ DecodeError(expected: "Float", found: "Int", path: ["1"]),
+ ]))
}