aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouis Pilfold <louis@lpil.uk>2022-01-09 18:59:42 +0000
committerLouis Pilfold <louis@lpil.uk>2022-01-09 18:59:42 +0000
commitfcdf32132d83c4b5d52d3d463bed2fc699649ab1 (patch)
tree5570a656bfc849f76bfdde8589e1789f1dcb3b8d
parent480e37150565898cbf2dfd12336df4998af28987 (diff)
downloadgleam_stdlib-fcdf32132d83c4b5d52d3d463bed2fc699649ab1.tar.gz
gleam_stdlib-fcdf32132d83c4b5d52d3d463bed2fc699649ab1.zip
Curry field
-rw-r--r--CHANGELOG.md3
-rw-r--r--src/gleam/dynamic.gleam22
2 files changed, 13 insertions, 12 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a70bc4e..1f4cd37 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,7 +3,8 @@
## v0.19.1 - 2022-01-09
- The `dynamic.dynamic` function now returns a result.
-- The `dynamic.result` and `dynamic.list` functions are now partially applied.
+- The `dynamic.result`, `dynamic.optional`, `dynamic.field`, and `dynamic.list`
+ functions are now partially applied.
## v0.19.0 - 2022-01-09
diff --git a/src/gleam/dynamic.gleam b/src/gleam/dynamic.gleam
index 50437e1..1157014 100644
--- a/src/gleam/dynamic.gleam
+++ b/src/gleam/dynamic.gleam
@@ -426,21 +426,21 @@ if javascript {
///
/// ```gleam
/// > import gleam/map
-/// > field(from(map.new("Hello", "World")), "Hello")
-/// Ok(Dynamic)
+/// > from(map.new("Hello", "World"))
+/// > |> field(named: "Hello", of: string)
+/// Ok("World")
///
-/// > field(from(123), "Hello")
+/// > from(123)
+/// > |> field("Hello", string)
/// Error([DecodeError(expected: "Map", found: "Int", path: [])])
/// ```
///
-pub fn field(
- from value: Dynamic,
- named name: a,
- of inner_type: Decoder(t),
-) -> Result(t, DecodeErrors) {
- try value = decode_field(value, name)
- inner_type(value)
- |> map_errors(push_path(_, name))
+pub fn field(named name: a, of inner_type: Decoder(t)) -> Decoder(t) {
+ fn(value) {
+ try value = decode_field(value, name)
+ inner_type(value)
+ |> map_errors(push_path(_, name))
+ }
}
if erlang {