Skip to main content

src/yum@yaml@dynamic.erl

-module(yum@yaml@dynamic).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/yum/yaml/dynamic.gleam").
-export([from_node/1]).

-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/yum/yaml/dynamic.gleam", 5).
?DOC(false).
-spec from_node(yum@yaml@node:node_()) -> gleam@dynamic:dynamic_().
from_node(Value) ->
    case yum@yaml@node:kind(Value) of
        null ->
            gleam@dynamic:nil();

        {bool, Value@1} ->
            gleam_stdlib:identity(Value@1);

        {int, Value@2} ->
            gleam_stdlib:identity(Value@2);

        {float, Value@3} ->
            gleam_stdlib:identity(Value@3);

        pos_inf ->
            gleam_stdlib:identity(<<".inf"/utf8>>);

        neg_inf ->
            gleam_stdlib:identity(<<"-.inf"/utf8>>);

        nan ->
            gleam_stdlib:identity(<<".nan"/utf8>>);

        {string, Value@4} ->
            gleam_stdlib:identity(Value@4);

        {sequence, Entries} ->
            _pipe = Entries,
            _pipe@1 = gleam@list:map(_pipe, fun from_node/1),
            erlang:list_to_tuple(_pipe@1);

        {mapping, Entries@1} ->
            _pipe@2 = Entries@1,
            _pipe@3 = gleam@list:map(
                _pipe@2,
                fun(Entry) ->
                    {Key, Value@5} = Entry,
                    {from_node(Key), from_node(Value@5)}
                end
            ),
            gleam@dynamic:properties(_pipe@3)
    end.