-module(gladvent@internal@runners). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([build_from_days_dir/1]). -spec to_module_name(binary()) -> binary(). to_module_name(File) -> _pipe = File, _pipe@1 = gleam@string:replace(_pipe, <<".gleam"/utf8>>, <<""/utf8>>), _pipe@2 = gleam@string:replace(_pipe@1, <<".erl"/utf8>>, <<""/utf8>>), gleam@string:replace(_pipe@2, <<"/"/utf8>>, <<"@"/utf8>>). -spec function_exists(integer(), binary(), gleam@erlang@atom:atom_(), binary()) -> {ok, fun((any()) -> any())} | {error, snag:snag()}. function_exists(Year, Filename, Mod, Func_name) -> case gladvent_ffi:module_exists(Mod) of false -> _pipe = [<<"module "/utf8>>, Filename, <<" not found"/utf8>>], _pipe@1 = gleam@string:concat(_pipe), snag:error(_pipe@1); true -> _pipe@2 = Func_name, _pipe@3 = erlang:binary_to_atom(_pipe@2), _pipe@4 = gladvent_ffi:function_arity_one_exists(Mod, _pipe@3), _pipe@5 = gleam@result:replace_error( _pipe@4, snag:new( <<<<<<<<<<<<<<"module "/utf8, "src/"/utf8>>/binary, (gleam@int:to_string(Year))/binary>>/binary, "/"/utf8>>/binary, Filename/binary>>/binary, " does not export a function \""/utf8>>/binary, Func_name/binary>>/binary, "/1\""/utf8>> ) ), snag:context(_pipe@5, <<"function missing"/utf8>>) end. -spec get_runner(integer(), binary()) -> {ok, {integer(), {fun((gleam@dynamic:dynamic_()) -> gleam@dynamic:dynamic_()), fun((gleam@dynamic:dynamic_()) -> gleam@dynamic:dynamic_()), gleam@option:option(fun((binary()) -> gleam@dynamic:dynamic_()))}}} | {error, snag:snag()}. get_runner(Year, Filename) -> gleam@result:then( begin _pipe = gleam@string:replace(Filename, <<"day_"/utf8>>, <<""/utf8>>), _pipe@1 = gleam@string:replace( _pipe, <<".gleam"/utf8>>, <<""/utf8>> ), _pipe@2 = gladvent@internal@parse:day(_pipe@1), snag:context( _pipe@2, gleam@string:append( <<"cannot create runner for "/utf8>>, Filename ) ) end, fun(Day) -> Module = begin _pipe@3 = (<<<<<<"aoc_"/utf8, (gleam@int:to_string(Year))/binary>>/binary, "/"/utf8>>/binary, Filename/binary>>), _pipe@4 = to_module_name(_pipe@3), erlang:binary_to_atom(_pipe@4) end, gleam@result:then( function_exists(Year, Filename, Module, <<"pt_1"/utf8>>), fun(Pt_1) -> gleam@result:then( function_exists(Year, Filename, Module, <<"pt_2"/utf8>>), fun(Pt_2) -> {ok, {Day, {Pt_1, Pt_2, gleam@option:from_result( function_exists( Year, Filename, Module, <<"parse"/utf8>> ) )}}} end ) end ) end ). -spec build_from_days_dir(integer()) -> {ok, gleam@dict:dict(integer(), {fun((gleam@dynamic:dynamic_()) -> gleam@dynamic:dynamic_()), fun((gleam@dynamic:dynamic_()) -> gleam@dynamic:dynamic_()), gleam@option:option(fun((binary()) -> gleam@dynamic:dynamic_()))})} | {error, snag:snag()}. build_from_days_dir(Year) -> _pipe = gladvent_ffi:find_files( <<"day_*.gleam"/utf8>>, <<"src/aoc_"/utf8, (gleam@int:to_string(Year))/binary>> ), _pipe@1 = gleam@list:try_map( _pipe, fun(_capture) -> get_runner(Year, _capture) end ), _pipe@2 = gleam@result:map(_pipe@1, fun maps:from_list/1), snag:context( _pipe@2, <<"failed to generate runners list from filesystem"/utf8>> ).