Current section
Files
Jump to
Current section
Files
src/gladvent@internal@parse.erl
-module(gladvent@internal@parse).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([int/1, day/1, days/1]).
-spec int(binary()) -> {ok, integer()} | {error, snag:snag()}.
int(S) ->
_pipe = S,
_pipe@1 = gleam@int:parse(_pipe),
gleam@result:replace_error(
_pipe@1,
snag:new(
<<<<"failed to parse \""/utf8, S/binary>>/binary, "\" as int"/utf8>>
)
).
-spec day(binary()) -> {ok, integer()} | {error, snag:snag()}.
day(S) ->
gleam@result:then(int(S), fun(I) -> case (I > 0) andalso (I < 26) of
true ->
{ok, I};
false ->
_pipe = (<<<<<<"invalid day value "/utf8, "'"/utf8>>/binary,
S/binary>>/binary,
"'"/utf8>>),
_pipe@1 = snag:error(_pipe),
snag:context(
_pipe@1,
<<"day must be an integer from 1 to 25"/utf8>>
)
end end).
-spec days(list(binary())) -> {ok, list(integer())} | {error, snag:snag()}.
days(L) ->
_pipe = gleam@list:try_map(L, fun day/1),
snag:context(_pipe, <<"could not map day values to integers"/utf8>>).