Current section
Files
Jump to
Current section
Files
src/yodel@properties.erl
-module(yodel@properties).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([new/0, get/2, insert/3, merge/2, fold/3, size/1, delete/2, insert_string/3, string/2, insert_int/3, int/2, insert_float/3, float/2, insert_bool/3, bool/2, insert_null/2, null/1]).
-export_type([properties/0, value/0, properties_error/0, type_error/0]).
-opaque properties() :: {properties, gleam@dict:dict(binary(), value())}.
-type value() :: {string_value, binary()} |
{int_value, integer()} |
{float_value, float()} |
{bool_value, boolean()} |
null_value.
-type properties_error() :: {path_not_found, binary()} |
{type_error, binary(), type_error()}.
-type type_error() :: {expected_string, value()} |
{expected_int, value()} |
{expected_float, value()} |
{expected_bool, value()}.
-file("src/yodel/properties.gleam", 32).
-spec new() -> properties().
new() ->
{properties, maps:new()}.
-file("src/yodel/properties.gleam", 36).
-spec get(properties(), binary()) -> {ok, value()} | {error, properties_error()}.
get(Props, Path) ->
_pipe = gleam_stdlib:map_get(erlang:element(2, Props), Path),
gleam@result:map_error(_pipe, fun(_) -> {path_not_found, Path} end).
-file("src/yodel/properties.gleam", 44).
-spec insert(properties(), binary(), value()) -> properties().
insert(Props, Path, Value) ->
{properties, gleam@dict:insert(erlang:element(2, Props), Path, Value)}.
-file("src/yodel/properties.gleam", 52).
-spec merge(properties(), properties()) -> properties().
merge(Old_props, New_props) ->
{properties,
maps:merge(erlang:element(2, Old_props), erlang:element(2, New_props))}.
-file("src/yodel/properties.gleam", 59).
-spec fold(properties(), QFS, fun((QFS, binary(), value()) -> QFS)) -> QFS.
fold(Props, Initial, Fun) ->
gleam@dict:fold(erlang:element(2, Props), Initial, Fun).
-file("src/yodel/properties.gleam", 67).
-spec size(properties()) -> integer().
size(Props) ->
maps:size(erlang:element(2, Props)).
-file("src/yodel/properties.gleam", 71).
-spec delete(properties(), list(yodel@path:path_segment())) -> properties().
delete(Props, Path) ->
{properties,
gleam@dict:delete(
erlang:element(2, Props),
yodel@path:path_to_string(Path)
)}.
-file("src/yodel/properties.gleam", 95).
-spec insert_string(properties(), binary(), binary()) -> properties().
insert_string(Props, Path, Value) ->
insert(Props, Path, {string_value, Value}).
-file("src/yodel/properties.gleam", 75).
-spec string(list(yodel@path:path_segment()), binary()) -> properties().
string(Path, Value) ->
insert_string(new(), yodel@path:path_to_string(Path), Value).
-file("src/yodel/properties.gleam", 103).
-spec insert_int(properties(), binary(), integer()) -> properties().
insert_int(Props, Path, Value) ->
insert(Props, Path, {int_value, Value}).
-file("src/yodel/properties.gleam", 79).
-spec int(list(yodel@path:path_segment()), integer()) -> properties().
int(Path, Value) ->
insert_int(new(), yodel@path:path_to_string(Path), Value).
-file("src/yodel/properties.gleam", 111).
-spec insert_float(properties(), binary(), float()) -> properties().
insert_float(Props, Path, Value) ->
insert(Props, Path, {float_value, Value}).
-file("src/yodel/properties.gleam", 83).
-spec float(list(yodel@path:path_segment()), float()) -> properties().
float(Path, Value) ->
insert_float(new(), yodel@path:path_to_string(Path), Value).
-file("src/yodel/properties.gleam", 119).
-spec insert_bool(properties(), binary(), boolean()) -> properties().
insert_bool(Props, Path, Value) ->
insert(Props, Path, {bool_value, Value}).
-file("src/yodel/properties.gleam", 87).
-spec bool(list(yodel@path:path_segment()), boolean()) -> properties().
bool(Path, Value) ->
insert_bool(new(), yodel@path:path_to_string(Path), Value).
-file("src/yodel/properties.gleam", 127).
-spec insert_null(properties(), binary()) -> properties().
insert_null(Props, Path) ->
insert(Props, Path, null_value).
-file("src/yodel/properties.gleam", 91).
-spec null(list(yodel@path:path_segment())) -> properties().
null(Path) ->
insert_null(new(), yodel@path:path_to_string(Path)).