-module(yodel@path). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/yodel/path.gleam"). -export([new/0, add_segment/2, add_index/2, path_to_string/1]). -export_type([path_segment/0]). -opaque path_segment() :: {key, binary()} | {index, integer()}. -file("src/yodel/path.gleam", 12). -spec new() -> list(path_segment()). new() -> gleam@list:new(). -file("src/yodel/path.gleam", 16). -spec add_segment(list(path_segment()), binary()) -> list(path_segment()). add_segment(Path, Segment) -> [{key, Segment} | Path]. -file("src/yodel/path.gleam", 20). -spec add_index(list(path_segment()), integer()) -> list(path_segment()). add_index(Path, Index) -> [{index, Index} | Path]. -file("src/yodel/path.gleam", 24). -spec path_to_string(list(path_segment())) -> binary(). path_to_string(Segments) -> _pipe = Segments, gleam@list:fold_right( _pipe, <<""/utf8>>, fun(Acc, Segment) -> case Segment of {key, Key} -> case Acc of <<""/utf8>> -> Key; _ -> <<<>/binary, Key/binary>> end; {index, Index} -> <<<<<>/binary, (erlang:integer_to_binary(Index))/binary>>/binary, "]"/utf8>> end end ).