Current section

Files

Jump to
telega src telega@models@common.erl
Raw

src/telega@models@common.erl

-module(telega@models@common).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([string_or_int_to_json/1, option_to_json_object_list/3]).
-export_type([int_or_string/0]).
-type int_or_string() :: {int, integer()} | {string, binary()}.
-spec string_or_int_to_json(int_or_string()) -> gleam@json:json().
string_or_int_to_json(Value) ->
case Value of
{int, Value@1} ->
gleam@json:int(Value@1);
{string, Value@2} ->
gleam@json:string(Value@2)
end.
-spec option_to_json_object_list(
gleam@option:option(OKE),
binary(),
fun((OKE) -> gleam@json:json())
) -> list({binary(), gleam@json:json()}).
option_to_json_object_list(Value, Field, Encoder) ->
_pipe = gleam@option:map(Value, fun(V) -> [{Field, Encoder(V)}] end),
gleam@option:unwrap(_pipe, []).