Current section

Files

Jump to
argamak src argamak@util.erl
Raw

src/argamak@util.erl

-module(argamak@util).
-compile(no_auto_import).
-export([record_to_string/1]).
-export_type([util_error/0]).
-type util_error() :: invalid_record.
-spec record_to_string(any()) -> {ok, binary()} | {error, util_error()}.
record_to_string(Record) ->
do_record_to_string(Record).
-spec do_record_to_string(any()) -> {ok, binary()} | {error, util_error()}.
do_record_to_string(Record) ->
case begin
_pipe = Record,
_pipe@1 = gleam@dynamic:from(_pipe),
_pipe@2 = (gleam@dynamic:any(
[fun gleam@erlang@atom:from_dynamic/1,
gleam@dynamic:element(0, fun gleam@erlang@atom:from_dynamic/1)]
))(_pipe@1),
gleam@result:replace_error(_pipe@2, invalid_record)
end of
{error, _try} -> {error, _try};
{ok, Atom} ->
Atom@1 = begin
_pipe@3 = Atom,
_pipe@4 = gleam@erlang@atom:to_string(_pipe@3),
_pipe@5 = gleam@string:split(_pipe@4, <<"_"/utf8>>),
_pipe@6 = gleam@list:flat_map(
_pipe@5,
fun(String) ->
{ok, {Grapheme@1, String@2}} = case gleam@string:pop_grapheme(
String
) of
{ok, {Grapheme, String@1}} -> {ok,
{Grapheme, String@1}};
_try@1 ->
erlang:error(#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _try@1,
module => <<"argamak/util"/utf8>>,
function => <<"do_record_to_string"/utf8>>,
line => 53})
end,
[gleam@string:uppercase(Grapheme@1), String@2]
end
),
gleam@string:concat(_pipe@6)
end,
{ok, Atom@1}
end.