Current section
Files
Jump to
Current section
Files
src/runners.erl
-module(runners).
-compile(no_auto_import).
-export([build_from_days_dir/0]).
-spec to_module(binary()) -> gleam@erlang@atom:atom_().
to_module(File) ->
_pipe = File,
_pipe@1 = gleam@string:replace(_pipe, <<".gleam"/utf8>>, <<""/utf8>>),
_pipe@2 = gleam@string:replace(_pipe@1, <<".erl"/utf8>>, <<""/utf8>>),
_pipe@3 = gleam@string:replace(_pipe@2, <<"/"/utf8>>, <<"@"/utf8>>),
gleam@erlang@atom:create_from_string(_pipe@3).
-spec get_runner(binary()) -> {ok,
{integer(),
fun((binary()) -> {integer(), integer()})}} |
{error, snag:snag()}.
get_runner(Filename) ->
case begin
_pipe = gleam@string:replace(Filename, <<"day_"/utf8>>, <<""/utf8>>),
_pipe@1 = gleam@string:replace(_pipe, <<".gleam"/utf8>>, <<""/utf8>>),
_pipe@2 = parse:day(_pipe@1),
snag:context(
_pipe@2,
gleam@string:append(<<"cannot create runner for "/utf8>>, Filename)
)
end of
{error, _try} -> {error, _try};
{ok, Day} ->
Run = begin
_pipe@3 = Filename,
_pipe@4 = gleam@string:append(<<"days/"/utf8>>, _pipe@3),
_pipe@5 = to_module(_pipe@4),
gladvent_ffi:get_run(_pipe@5)
end,
{ok, {Day, Run}}
end.
-spec build_from_days_dir() -> {ok,
gleam@map:map_(integer(), fun((binary()) -> {integer(),
integer()}))} |
{error, snag:snag()}.
build_from_days_dir() ->
_pipe = gladvent_ffi:find_files(
<<"day_*.gleam"/utf8>>,
<<"src/days/"/utf8>>
),
_pipe@1 = gleam@list:try_map(_pipe, fun get_runner/1),
_pipe@2 = gleam@result:map(_pipe@1, fun gleam@map:from_list/1),
snag:context(
_pipe@2,
<<"failed to generate runners list from filesystem"/utf8>>
).