From c5b63d981600a81ed51daa8e9df445d1ec4e1a8c Mon Sep 17 00:00:00 2001 From: Hayleigh Thompson Date: Fri, 31 Jul 2026 22:51:35 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8Create=20a=20lil=20util=20for=20handli?= =?UTF-8?q?ng=20optional=20fields=20in=20decoders.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/at/internal/decoding.gleam | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/at/internal/decoding.gleam diff --git a/src/at/internal/decoding.gleam b/src/at/internal/decoding.gleam new file mode 100644 index 0000000..dd9d5ea --- /dev/null +++ b/src/at/internal/decoding.gleam @@ -0,0 +1,14 @@ +// IMPORTS --------------------------------------------------------------------- + +import gleam/dynamic/decode.{type Decoder} +import gleam/option.{type Option, None, Some} + +/// +/// +pub fn optional_field( + name: String, + decoder: Decoder(a), + next: fn(Option(a)) -> Decoder(b), +) -> Decoder(b) { + decode.optional_field(name, None, decode.map(decoder, Some), next) +} -- 2.51.2