-module(oas@generator@lookup). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/oas/generator/lookup.gleam"). -export([then/2, seq/1, fold/3, map_fold/3]). -export_type([lookup/1]). -type lookup(PKK) :: {lookup, binary(), fun((gleam@option:option(binary()), binary()) -> lookup(PKK))} | {done, PKK}. -file("src/oas/generator/lookup.gleam", 9). -spec then(lookup(PKL), fun((PKL) -> lookup(PKN))) -> lookup(PKN). then(Lookup, Next) -> case Lookup of {lookup, Ref, Inner} -> {lookup, Ref, fun(Mod, Name) -> then(Inner(Mod, Name), Next) end}; {done, Value} -> Next(Value) end. -file("src/oas/generator/lookup.gleam", 21). -spec do_seq(list(lookup(PLY)), list(PLY)) -> lookup(list(PLY)). do_seq(Lookups, Acc) -> case Lookups of [] -> {done, lists:reverse(Acc)}; [{done, Value} | Rest] -> do_seq(Rest, [Value | Acc]); [{lookup, Ref, Inner} | Rest@1] -> {lookup, Ref, fun(Mod, Name) -> do_seq([Inner(Mod, Name) | Rest@1], Acc) end} end. -file("src/oas/generator/lookup.gleam", 17). -spec seq(list(lookup(PKQ))) -> lookup(list(PKQ)). seq(Lookups) -> do_seq(Lookups, []). -file("src/oas/generator/lookup.gleam", 30). -spec fold(list(PKY), PLA, fun((PLA, PKY) -> lookup(PLA))) -> lookup(PLA). fold(Items, Initial, Func) -> case Items of [] -> {done, Initial}; [Next | Rest] -> then(Func(Initial, Next), fun(Acc) -> fold(Rest, Acc, Func) end) end. -file("src/oas/generator/lookup.gleam", 44). -spec map_fold(list(PLD), PLF, fun((PLF, PLD) -> lookup({PLF, PLG}))) -> lookup({PLF, list(PLG)}). map_fold(Items, Initial, Func) -> then( fold( Items, {Initial, []}, fun(Acc, Item) -> {Inner, Buffer} = Acc, then( Func(Inner, Item), fun(_use0) -> {Inner@1, Next} = _use0, {done, {Inner@1, [Next | Buffer]}} end ) end ), fun(_use0@1) -> {Inner@2, Buffer@1} = _use0@1, {done, {Inner@2, lists:reverse(Buffer@1)}} end ).