diff options
author | Louis Pilfold <louis@lpil.uk> | 2022-01-09 18:54:50 +0000 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2022-01-09 18:54:50 +0000 |
commit | 480e37150565898cbf2dfd12336df4998af28987 (patch) | |
tree | 11be2deff2b7943239949650be95c5c0bd07a2b5 | |
parent | 855d5021bd991ddc6bfd2a2a1499c3ddce94b675 (diff) | |
download | gleam_stdlib-480e37150565898cbf2dfd12336df4998af28987.tar.gz gleam_stdlib-480e37150565898cbf2dfd12336df4998af28987.zip |
Curry optional
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | src/gleam/dynamic.gleam | 25 |
2 files changed, 15 insertions, 12 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 764e087..a70bc4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## v0.19.1 - 2022-01-09 - The `dynamic.dynamic` function now returns a result. -- The `dynamic.result` function is now partially applied. +- The `dynamic.result` 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 1cf8991..50437e1 100644 --- a/src/gleam/dynamic.gleam +++ b/src/gleam/dynamic.gleam @@ -372,30 +372,33 @@ pub fn list( /// ## Examples /// /// ```gleam -/// > option(from("Hello"), string) +/// > from("Hello") +/// > |> option(string) /// Ok(Some("Hello")) /// -/// > option(from("Hello"), string) +/// > from("Hello") +/// > |> option(string) /// Ok(Some("Hello")) /// -/// > option(from(atom.from_string("null")), string) +/// > from(atom.from_string("null")) +/// > |> option(string) /// Ok(None) /// -/// > option(from(atom.from_string("nil")), string) +/// > from(atom.from_string("nil")) +/// > |> option(string) /// Ok(None) /// -/// > option(from(atom.from_string("undefined")), string) +/// > from(atom.from_string("undefined")) +/// > |> option(string) /// Ok(None) /// -/// > option(from(123), string) +/// > from(123) +/// > |> option(string) /// Error([DecodeError(expected: "BitString", found: "Int", path: [])]) /// ```gleam /// -pub fn optional( - from value: Dynamic, - of decode: Decoder(inner), -) -> Result(Option(inner), DecodeErrors) { - decode_optional(value, decode) +pub fn optional(of decode: Decoder(inner)) -> Decoder(Option(inner)) { + fn(value) { decode_optional(value, decode) } } if erlang { |