Packages
caffeine_lang
5.4.2
6.3.1
6.3.0
6.2.2
6.2.1
6.2.0
6.1.2
6.1.1
6.1.0
6.0.0
5.6.0
5.5.0
5.4.4
5.4.3
5.4.2
5.4.1
5.4.0
5.3.0
5.2.0
5.1.1
5.1.0
5.0.12
5.0.11
5.0.10
5.0.8
5.0.7
5.0.6
5.0.5
5.0.4
5.0.1
5.0.0
4.10.0
4.9.0
4.8.3
4.8.2
4.8.1
4.8.0
4.7.9
4.7.8
4.7.7
4.7.6
4.7.5
4.6.7
4.6.6
4.6.5
4.6.4
4.6.3
4.6.2
4.6.0
4.5.1
4.5.0
4.4.4
4.4.3
4.4.1
4.4.0
4.3.7
4.3.6
3.0.6
3.0.5
3.0.4
3.0.3
3.0.2
3.0.1
3.0.0
2.0.5
2.0.4
2.0.3
2.0.2
2.0.1
2.0.0
1.0.2
1.0.1
0.1.0
0.0.24
0.0.23
0.0.22
0.0.21
0.0.20
0.0.19
0.0.18
0.0.17
0.0.16
0.0.15
0.0.14
0.0.13
0.0.12
0.0.11
0.0.10
0.0.9
0.0.8
0.0.7
0.0.6
0.0.5
0.0.4
0.0.2
0.0.1
A compiler for generating reliability artifacts from service expectation definitions.
Current section
Files
Jump to
Current section
Files
src/caffeine_lang@value.erl
-module(caffeine_lang@value).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/caffeine_lang/value.gleam").
-export([to_string/1, to_preview_string/1, classify/1, extract_string/1, extract_int/1, extract_float/1, extract_percentage/1, extract_bool/1, extract_dict/1, extract_string_dict/1]).
-export_type([value/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-type value() :: {string_value, binary()} |
{int_value, integer()} |
{float_value, float()} |
{percentage_value, float()} |
{bool_value, boolean()} |
{list_value, list(value())} |
{dict_value, gleam@dict:dict(binary(), value())} |
nil_value.
-file("src/caffeine_lang/value.gleam", 24).
?DOC(false).
-spec to_string(value()) -> binary().
to_string(Value) ->
case Value of
{string_value, S} ->
S;
{int_value, I} ->
erlang:integer_to_binary(I);
{float_value, F} ->
gleam_stdlib:float_to_string(F);
{percentage_value, F@1} ->
gleam_stdlib:float_to_string(F@1);
{bool_value, true} ->
<<"true"/utf8>>;
{bool_value, false} ->
<<"false"/utf8>>;
{list_value, Items} ->
<<<<"["/utf8,
(begin
_pipe = Items,
_pipe@1 = gleam@list:map(_pipe, fun to_string/1),
gleam@string:join(_pipe@1, <<", "/utf8>>)
end)/binary>>/binary,
"]"/utf8>>;
{dict_value, D} ->
<<<<"{"/utf8,
(begin
_pipe@2 = D,
_pipe@3 = maps:to_list(_pipe@2),
_pipe@4 = gleam@list:map(
_pipe@3,
fun(Pair) ->
<<<<(erlang:element(1, Pair))/binary,
": "/utf8>>/binary,
(to_string(erlang:element(2, Pair)))/binary>>
end
),
gleam@string:join(_pipe@4, <<", "/utf8>>)
end)/binary>>/binary,
"}"/utf8>>;
nil_value ->
<<""/utf8>>
end.
-file("src/caffeine_lang/value.gleam", 47).
?DOC(false).
-spec to_preview_string(value()) -> binary().
to_preview_string(Value) ->
case Value of
{string_value, S} ->
<<<<"\""/utf8, S/binary>>/binary, "\""/utf8>>;
{int_value, I} ->
erlang:integer_to_binary(I);
{float_value, F} ->
gleam_stdlib:float_to_string(F);
{percentage_value, F@1} ->
<<(gleam_stdlib:float_to_string(F@1))/binary, "%"/utf8>>;
{bool_value, true} ->
<<"true"/utf8>>;
{bool_value, false} ->
<<"false"/utf8>>;
{list_value, _} ->
<<"List"/utf8>>;
{dict_value, _} ->
<<"Dict"/utf8>>;
nil_value ->
<<"Nil"/utf8>>
end.
-file("src/caffeine_lang/value.gleam", 63).
?DOC(false).
-spec classify(value()) -> binary().
classify(Value) ->
case Value of
{string_value, _} ->
<<"String"/utf8>>;
{int_value, _} ->
<<"Int"/utf8>>;
{float_value, _} ->
<<"Float"/utf8>>;
{percentage_value, _} ->
<<"Percentage"/utf8>>;
{bool_value, _} ->
<<"Bool"/utf8>>;
{list_value, _} ->
<<"List"/utf8>>;
{dict_value, _} ->
<<"Dict"/utf8>>;
nil_value ->
<<"Nil"/utf8>>
end.
-file("src/caffeine_lang/value.gleam", 78).
?DOC(false).
-spec extract_string(value()) -> {ok, binary()} | {error, nil}.
extract_string(Value) ->
case Value of
{string_value, S} ->
{ok, S};
_ ->
{error, nil}
end.
-file("src/caffeine_lang/value.gleam", 87).
?DOC(false).
-spec extract_int(value()) -> {ok, integer()} | {error, nil}.
extract_int(Value) ->
case Value of
{int_value, I} ->
{ok, I};
_ ->
{error, nil}
end.
-file("src/caffeine_lang/value.gleam", 96).
?DOC(false).
-spec extract_float(value()) -> {ok, float()} | {error, nil}.
extract_float(Value) ->
case Value of
{float_value, F} ->
{ok, F};
_ ->
{error, nil}
end.
-file("src/caffeine_lang/value.gleam", 105).
?DOC(false).
-spec extract_percentage(value()) -> {ok, float()} | {error, nil}.
extract_percentage(Value) ->
case Value of
{percentage_value, F} ->
{ok, F};
_ ->
{error, nil}
end.
-file("src/caffeine_lang/value.gleam", 114).
?DOC(false).
-spec extract_bool(value()) -> {ok, boolean()} | {error, nil}.
extract_bool(Value) ->
case Value of
{bool_value, B} ->
{ok, B};
_ ->
{error, nil}
end.
-file("src/caffeine_lang/value.gleam", 123).
?DOC(false).
-spec extract_dict(value()) -> {ok, gleam@dict:dict(binary(), value())} |
{error, nil}.
extract_dict(Value) ->
case Value of
{dict_value, D} ->
{ok, D};
_ ->
{error, nil}
end.
-file("src/caffeine_lang/value.gleam", 133).
?DOC(false).
-spec extract_string_dict(value()) -> {ok, gleam@dict:dict(binary(), binary())} |
{error, nil}.
extract_string_dict(Value) ->
case Value of
{dict_value, D} ->
_pipe = D,
_pipe@1 = maps:to_list(_pipe),
_pipe@2 = gleam@list:try_map(
_pipe@1,
fun(Pair) -> case erlang:element(2, Pair) of
{string_value, S} ->
{ok, {erlang:element(1, Pair), S}};
_ ->
{error, nil}
end end
),
gleam@result:map(_pipe@2, fun maps:from_list/1);
_ ->
{error, nil}
end.