Skip to content

Commit fcdf321

Browse files
committed
Curry field
1 parent 480e371 commit fcdf321

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
## v0.19.1 - 2022-01-09
44

55
- The `dynamic.dynamic` function now returns a result.
6-
- The `dynamic.result` and `dynamic.list` functions are now partially applied.
6+
- The `dynamic.result`, `dynamic.optional`, `dynamic.field`, and `dynamic.list`
7+
functions are now partially applied.
78

89
## v0.19.0 - 2022-01-09
910

src/gleam/dynamic.gleam

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -426,21 +426,21 @@ if javascript {
426426
///
427427
/// ```gleam
428428
/// > import gleam/map
429-
/// > field(from(map.new("Hello", "World")), "Hello")
430-
/// Ok(Dynamic)
429+
/// > from(map.new("Hello", "World"))
430+
/// > |> field(named: "Hello", of: string)
431+
/// Ok("World")
431432
///
432-
/// > field(from(123), "Hello")
433+
/// > from(123)
434+
/// > |> field("Hello", string)
433435
/// Error([DecodeError(expected: "Map", found: "Int", path: [])])
434436
/// ```
435437
///
436-
pub fn field(
437-
from value: Dynamic,
438-
named name: a,
439-
of inner_type: Decoder(t),
440-
) -> Result(t, DecodeErrors) {
441-
try value = decode_field(value, name)
442-
inner_type(value)
443-
|> map_errors(push_path(_, name))
438+
pub fn field(named name: a, of inner_type: Decoder(t)) -> Decoder(t) {
439+
fn(value) {
440+
try value = decode_field(value, name)
441+
inner_type(value)
442+
|> map_errors(push_path(_, name))
443+
}
444444
}
445445

446446
if erlang {

0 commit comments

Comments
 (0)