-module(parse). -compile(no_auto_import). -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) -> case int(S) of {error, _try} -> {error, _try}; {ok, 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) -> case L of [] -> snag:error(<<"no days selected"/utf8>>); _@1 -> _pipe = gleam@list:try_map(L, fun day/1), snag:context(_pipe, <<"could not map day values to integers"/utf8>>) end.