From 480e37150565898cbf2dfd12336df4998af28987 Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Sun, 9 Jan 2022 18:54:50 +0000 Subject: Curry optional --- src/gleam/dynamic.gleam | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'src') 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 { -- cgit v1.2.3