Current section
Files
Jump to
Current section
Files
src/kitazith@internal@json_helper.erl
-module(kitazith@internal@json_helper).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/kitazith/internal/json_helper.gleam").
-export([object_omit_none/1, optional/3]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(false).
-file("src/kitazith/internal/json_helper.gleam", 5).
?DOC(false).
-spec object_omit_none(list(gleam@option:option({binary(), gleam@json:json()}))) -> gleam@json:json().
object_omit_none(Fields) ->
_pipe = Fields,
_pipe@1 = gleam@list:filter_map(_pipe, fun(Field) -> case Field of
{some, Pair} ->
{ok, Pair};
none ->
{error, nil}
end end),
gleam@json:object(_pipe@1).
-file("src/kitazith/internal/json_helper.gleam", 16).
?DOC(false).
-spec optional(
binary(),
gleam@option:option(DZU),
fun((DZU) -> gleam@json:json())
) -> gleam@option:option({binary(), gleam@json:json()}).
optional(Key, Value, Encoder) ->
case Value of
{some, V} ->
{some, {Key, Encoder(V)}};
none ->
none
end.