aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouis Pilfold <louis@lpil.uk>2022-01-09 18:52:02 +0000
committerLouis Pilfold <louis@lpil.uk>2022-01-09 18:52:02 +0000
commit855d5021bd991ddc6bfd2a2a1499c3ddce94b675 (patch)
tree5e4f37bbd657a264545ba131db1c4987b3a87f9c
parentb68260179e2e17930dfb0604fc2b26355fc79173 (diff)
downloadgleam_stdlib-855d5021bd991ddc6bfd2a2a1499c3ddce94b675.tar.gz
gleam_stdlib-855d5021bd991ddc6bfd2a2a1499c3ddce94b675.zip
Curry list
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/gleam/dynamic.gleam24
-rw-r--r--test/gleam/dynamic_test.gleam2
3 files changed, 16 insertions, 11 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 796964d..764e087 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,7 @@
## v0.19.1 - 2022-01-09
- The `dynamic.dynamic` function now returns a result.
+- The `dynamic.result` function is now partially applied.
## v0.19.0 - 2022-01-09
diff --git a/src/gleam/dynamic.gleam b/src/gleam/dynamic.gleam
index 44e6852..1cf8991 100644
--- a/src/gleam/dynamic.gleam
+++ b/src/gleam/dynamic.gleam
@@ -67,7 +67,7 @@ if javascript {
/// when you need to give a decoder function but you don't actually care what
/// the to-decode value is.
///
-pub fn dynamic(term: Dynamic) -> Decoder(Dynamic) {
+pub fn dynamic() -> Decoder(Dynamic) {
Ok
}
@@ -342,24 +342,28 @@ pub fn result(
/// ## Examples
///
/// ```gleam
-/// > list(from(["a", "b", "c"]), of: string)
+/// > from(["a", "b", "c"])
+/// > |> list(of: string)
/// Ok(["a", "b", "c"])
///
-/// > list(from([1, 2, 3]), of: string)
+/// > from([1, 2, 3])
+/// > |> list(of: string)
/// Error([DecodeError(expected: "String", found: "Int", path: [])])
///
-/// > list(from("ok"), of: string)
+/// > from("ok")
+/// > |> list(of: string)
/// Error([DecodeError(expected: "List", found: "String", path: [])])
/// ```
///
pub fn list(
- from dynamic: Dynamic,
of decoder_type: fn(Dynamic) -> Result(inner, DecodeErrors),
-) -> Result(List(inner), DecodeErrors) {
- try list = shallow_list(dynamic)
- list
- |> list.try_map(decoder_type)
- |> map_errors(push_path(_, "*"))
+) -> Decoder(List(inner)) {
+ fn(dynamic) {
+ try list = shallow_list(dynamic)
+ list
+ |> list.try_map(decoder_type)
+ |> map_errors(push_path(_, "*"))
+ }
}
/// Checks to see if a `Dynamic` value is a nullable version of a particular
diff --git a/test/gleam/dynamic_test.gleam b/test/gleam/dynamic_test.gleam
index f08f097..cbf58cf 100644
--- a/test/gleam/dynamic_test.gleam
+++ b/test/gleam/dynamic_test.gleam
@@ -192,7 +192,7 @@ pub fn list_test() {
[[1], [2], [3]]
|> dynamic.from
- |> dynamic.list(dynamic.list(_, dynamic.int))
+ |> dynamic.list(dynamic.list(dynamic.int))
|> should.equal(Ok([[1], [2], [3]]))
1