-module(shine_tree). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([single/1, size/1, first/1, last/1, try_map/2, fold_r_until/3, try_foldr/3, any/2, contains/2, all/2, reverse/1, append/2, prepend/2, concat/1, fold_l_until/3, try_foldl/3, find/2, find_map/2, get/2, from_list/1, range/2, shift/1, equals/2, pop/1, unshift/2, push/2, map/2, fold_r/3, filter/2, to_list/1, fold_l/3, count/2, each/2, filter_map/2, sort/2, group/2]). -export_type([shine_tree/1, node_/1]). -opaque shine_tree(IRK) :: empty | {single, IRK} | {deep, integer(), node_(IRK), shine_tree(node_(IRK)), node_(IRK)}. -type node_(IRL) :: {one, IRL} | {two, IRL, IRL} | {three, IRL, IRL, IRL} | {four, IRL, IRL, IRL, IRL}. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 50). -spec fold_l_node(IRT, node_(IRR), fun((IRT, IRR) -> IRT)) -> IRT. fold_l_node(V, Node, F) -> case Node of {one, W} -> F(V, W); {two, W@1, X} -> _pipe = V, _pipe@1 = F(_pipe, W@1), F(_pipe@1, X); {three, W@2, X@1, Y} -> _pipe@2 = V, _pipe@3 = F(_pipe@2, W@2), _pipe@4 = F(_pipe@3, X@1), F(_pipe@4, Y); {four, W@3, X@2, Y@1, Z} -> _pipe@5 = V, _pipe@6 = F(_pipe@5, W@3), _pipe@7 = F(_pipe@6, X@2), _pipe@8 = F(_pipe@7, Y@1), F(_pipe@8, Z) end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 105). -spec fold_r_node(ISF, node_(ISD), fun((ISF, ISD) -> ISF)) -> ISF. fold_r_node(V, Node, F) -> case Node of {one, W} -> F(V, W); {two, W@1, X} -> _pipe = V, _pipe@1 = F(_pipe, X), F(_pipe@1, W@1); {three, W@2, X@1, Y} -> _pipe@2 = V, _pipe@3 = F(_pipe@2, Y), _pipe@4 = F(_pipe@3, X@1), F(_pipe@4, W@2); {four, W@3, X@2, Y@1, Z} -> _pipe@5 = V, _pipe@6 = F(_pipe@5, Z), _pipe@7 = F(_pipe@6, Y@1), _pipe@8 = F(_pipe@7, X@2), F(_pipe@8, W@3) end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 155). -spec map_node(node_(ISO), fun((ISO) -> ISQ)) -> node_(ISQ). map_node(Node, F) -> case Node of {one, W} -> {one, F(W)}; {two, W@1, X} -> {two, F(W@1), F(X)}; {three, W@2, X@1, Y} -> {three, F(W@2), F(X@1), F(Y)}; {four, W@3, X@2, Y@1, Z} -> {four, F(W@3), F(X@2), F(Y@1), F(Z)} end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 255). -spec pop_node(node_(ITJ)) -> {ok, {ITJ, node_(ITJ)}} | {error, nil}. pop_node(Node) -> case Node of {two, U, V} -> {ok, {V, {one, U}}}; {three, U@1, V@1, W} -> {ok, {W, {two, U@1, V@1}}}; {four, U@2, V@2, W@1, X} -> {ok, {X, {three, U@2, V@2, W@1}}}; _ -> {error, nil} end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 304). -spec shift_node(node_(ITR)) -> {ok, {ITR, node_(ITR)}} | {error, nil}. shift_node(Node) -> case Node of {two, U, V} -> {ok, {U, {one, V}}}; {three, U@1, V@1, W} -> {ok, {U@1, {two, V@1, W}}}; {four, U@2, V@2, W@1, X} -> {ok, {U@2, {three, V@2, W@1, X}}}; _ -> {error, nil} end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 428). -spec do_chunk_values(list(IUQ), list(node_(IUQ)), integer()) -> {node_(IUQ), list(node_(IUQ)), integer()}. do_chunk_values(Values, Acc, Count) -> case Values of [] -> erlang:error(#{gleam_error => panic, message => <<"This is impossible!"/utf8>>, module => <<"shine_tree"/utf8>>, function => <<"do_chunk_values"/utf8>>, line => 434}); [A] -> {{one, A}, Acc, Count + 1}; [A@1, B] -> {{two, A@1, B}, Acc, Count + 2}; [A@2, B@1, C] -> {{three, A@2, B@1, C}, Acc, Count + 3}; [A@3, B@2, C@1, D] -> {{four, A@3, B@2, C@1, D}, Acc, Count + 4}; [A@4, B@3, C@2, D@1 | Rest] -> do_chunk_values(Rest, [{four, A@4, B@3, C@2, D@1} | Acc], Count + 4) end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 481). -spec do_chunk_values_reverse(list(IVA), list(node_(IVA)), integer()) -> {node_(IVA), list(node_(IVA)), integer()}. do_chunk_values_reverse(Items, Acc, Count) -> case Items of [] -> erlang:error(#{gleam_error => panic, message => <<"This is impossible!"/utf8>>, module => <<"shine_tree"/utf8>>, function => <<"do_chunk_values_reverse"/utf8>>, line => 483}); [A] -> {{one, A}, Acc, Count + 1}; [A@1, B] -> {{two, B, A@1}, Acc, Count + 2}; [A@2, B@1, C] -> {{three, C, B@1, A@2}, Acc, Count + 3}; [A@3, B@2, C@1, D] -> {{four, D, C@1, B@2, A@3}, Acc, Count + 4}; [A@4, B@3, C@2, D@1 | Rest] -> do_chunk_values_reverse( Rest, [{four, D@1, C@2, B@3, A@4} | Acc], Count + 4 ) end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 537). -spec reverse_node(node_(IWE)) -> node_(IWE). reverse_node(Node) -> case Node of {two, A, B} -> {two, B, A}; {three, A@1, B@1, C} -> {three, C, B@1, A@1}; {four, A@2, B@2, C@1, D} -> {four, D, C@1, B@2, A@2}; Node@1 -> Node@1 end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 548). -spec single(IWH) -> shine_tree(IWH). single(U) -> {single, U}. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 556). -spec size(shine_tree(any())) -> integer(). size(Tree) -> case Tree of empty -> 0; {single, _} -> 1; {deep, A, _, _, _} -> A end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 597). -spec all_node(node_(IWP), fun((IWP) -> boolean())) -> boolean(). all_node(Node, F) -> case Node of {one, A} -> F(A); {two, A@1, B} -> F(A@1) andalso F(B); {three, A@2, B@1, C} -> (F(A@2) andalso F(B@1)) andalso F(C); {four, A@3, B@2, C@1, D} -> ((F(A@3) andalso F(B@2)) andalso F(C@1)) andalso F(D) end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 638). -spec any_node(node_(IWV), fun((IWV) -> boolean())) -> boolean(). any_node(Node, F) -> case Node of {one, A} -> F(A); {two, A@1, B} -> F(A@1) orelse F(B); {three, A@2, B@1, C} -> (F(A@2) orelse F(B@1)) orelse F(C); {four, A@3, B@2, C@1, D} -> ((F(A@3) orelse F(B@2)) orelse F(C@1)) orelse F(D) end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 676). -spec unwrap_fold_until(gleam@list:continue_or_stop(IXI)) -> IXI. unwrap_fold_until(V) -> case V of {stop, V@1} -> V@1; {continue, V@1} -> V@1 end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 777). -spec try_continue( gleam@list:continue_or_stop(IYR), fun((IYR) -> gleam@list:continue_or_stop(IYR)) ) -> gleam@list:continue_or_stop(IYR). try_continue(V, F) -> case V of {continue, V@1} -> F(V@1); V@2 -> V@2 end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 784). -spec do_fold_node_l_until( node_(IYV), IYY, fun((IYY, IYV) -> gleam@list:continue_or_stop(IYY)) ) -> gleam@list:continue_or_stop(IYY). do_fold_node_l_until(Node, V, F) -> case Node of {one, A} -> F(V, A); {two, A@1, B} -> try_continue(F(V, A@1), fun(V@1) -> F(V@1, B) end); {three, A@2, B@1, C} -> try_continue( F(V, A@2), fun(V@2) -> try_continue(F(V@2, B@1), fun(V@3) -> F(V@3, C) end) end ); {four, A@3, B@2, C@1, D} -> try_continue( F(V, A@3), fun(V@4) -> try_continue( F(V@4, B@2), fun(V@5) -> try_continue(F(V@5, C@1), fun(V@6) -> F(V@6, D) end) end ) end ) end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 806). -spec do_fold_node_r_until( node_(IZB), IZE, fun((IZE, IZB) -> gleam@list:continue_or_stop(IZE)) ) -> gleam@list:continue_or_stop(IZE). do_fold_node_r_until(Node, V, F) -> case Node of {one, A} -> F(V, A); {two, B, A@1} -> try_continue(F(V, A@1), fun(V@1) -> F(V@1, B) end); {three, C, B@1, A@2} -> try_continue( F(V, A@2), fun(V@2) -> try_continue(F(V@2, B@1), fun(V@3) -> F(V@3, C) end) end ); {four, D, C@1, B@2, A@3} -> try_continue( F(V, A@3), fun(V@4) -> try_continue( F(V@4, B@2), fun(V@5) -> try_continue(F(V@5, C@1), fun(V@6) -> F(V@6, D) end) end ) end ) end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 934). -spec range_4(integer()) -> node_(integer()). range_4(Start) -> {four, Start, Start + 1, Start + 2, Start + 3}. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 938). -spec range_3(integer()) -> node_(integer()). range_3(Start) -> {three, Start, Start + 1, Start + 2}. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 942). -spec range_2(integer()) -> node_(integer()). range_2(Start) -> {two, Start, Start + 1}. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 988). -spec first(shine_tree(IZZ)) -> {ok, IZZ} | {error, nil}. first(Tree) -> case Tree of {deep, _, {one, U}, _, _} -> {ok, U}; {deep, _, {two, U@1, _}, _, _} -> {ok, U@1}; {deep, _, {three, U@2, _, _}, _, _} -> {ok, U@2}; {deep, _, {four, U@3, _, _, _}, _, _} -> {ok, U@3}; {single, U@4} -> {ok, U@4}; _ -> {error, nil} end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 1003). -spec last(shine_tree(JAD)) -> {ok, JAD} | {error, nil}. last(Tree) -> case Tree of {deep, _, _, _, {one, U}} -> {ok, U}; {deep, _, _, _, {two, _, U@1}} -> {ok, U@1}; {deep, _, _, _, {three, _, _, U@2}} -> {ok, U@2}; {deep, _, _, _, {four, _, _, _, U@3}} -> {ok, U@3}; {single, U@4} -> {ok, U@4}; _ -> {error, nil} end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 1033). -spec do_group_by_node( gleam@dict:dict(JAN, list(JAO)), node_(JAO), fun((JAO) -> JAN) ) -> gleam@dict:dict(JAN, list(JAO)). do_group_by_node(Final_dict, Item, F) -> case Item of {one, U} -> U_key = F(U), U_list = [U | begin _pipe = gleam_stdlib:map_get(Final_dict, U_key), gleam@result:unwrap(_pipe, []) end], gleam@dict:insert(Final_dict, U_key, U_list); {two, U@1, V} -> U_key@1 = F(U@1), V_key = F(V), U_list@1 = [U@1 | begin _pipe@1 = gleam_stdlib:map_get(Final_dict, U_key@1), gleam@result:unwrap(_pipe@1, []) end], gleam@dict:insert(Final_dict, U_key@1, U_list@1), V_list = [V | begin _pipe@2 = gleam_stdlib:map_get(Final_dict, V_key), gleam@result:unwrap(_pipe@2, []) end], gleam@dict:insert(Final_dict, V_key, V_list); {three, U@2, V@1, W} -> U_key@2 = F(U@2), V_key@1 = F(V@1), W_key = F(W), U_list@2 = [U@2 | begin _pipe@3 = gleam_stdlib:map_get(Final_dict, U_key@2), gleam@result:unwrap(_pipe@3, []) end], gleam@dict:insert(Final_dict, U_key@2, U_list@2), V_list@1 = [V@1 | begin _pipe@4 = gleam_stdlib:map_get(Final_dict, V_key@1), gleam@result:unwrap(_pipe@4, []) end], gleam@dict:insert(Final_dict, V_key@1, V_list@1), W_list = [W | begin _pipe@5 = gleam_stdlib:map_get(Final_dict, W_key), gleam@result:unwrap(_pipe@5, []) end], gleam@dict:insert(Final_dict, W_key, W_list); {four, U@3, V@2, W@1, X} -> U_key@3 = F(U@3), V_key@2 = F(V@2), W_key@1 = F(W@1), X_key = F(X), U_list@3 = [U@3 | begin _pipe@6 = gleam_stdlib:map_get(Final_dict, U_key@3), gleam@result:unwrap(_pipe@6, []) end], gleam@dict:insert(Final_dict, U_key@3, U_list@3), V_list@2 = [V@2 | begin _pipe@7 = gleam_stdlib:map_get(Final_dict, V_key@2), gleam@result:unwrap(_pipe@7, []) end], gleam@dict:insert(Final_dict, V_key@2, V_list@2), W_list@1 = [W@1 | begin _pipe@8 = gleam_stdlib:map_get(Final_dict, W_key@1), gleam@result:unwrap(_pipe@8, []) end], gleam@dict:insert(Final_dict, W_key@1, W_list@1), X_list = [X | begin _pipe@9 = gleam_stdlib:map_get(Final_dict, X_key), gleam@result:unwrap(_pipe@9, []) end], gleam@dict:insert(Final_dict, X_key, X_list) end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 1148). -spec node_size(node_(any())) -> integer(). node_size(Node) -> case Node of {one, _} -> 1; {two, _, _} -> 2; {three, _, _, _} -> 3; {four, _, _, _, _} -> 4 end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 1132). -spec get_node(integer(), node_(JBK)) -> gleam@list:continue_or_stop({ok, JBK} | {error, integer()}). get_node(Index, Node) -> case {Node, Index} of {{one, U}, 0} -> {stop, {ok, U}}; {{two, U@1, _}, 0} -> {stop, {ok, U@1}}; {{two, _, V}, 1} -> {stop, {ok, V}}; {{three, U@2, _, _}, 0} -> {stop, {ok, U@2}}; {{three, _, V@1, _}, 1} -> {stop, {ok, V@1}}; {{three, _, _, W}, 2} -> {stop, {ok, W}}; {{four, U@3, _, _, _}, 0} -> {stop, {ok, U@3}}; {{four, _, V@2, _, _}, 1} -> {stop, {ok, V@2}}; {{four, _, _, W@1, _}, 2} -> {stop, {ok, W@1}}; {{four, _, _, _, X}, 3} -> {stop, {ok, X}}; {Node@1, _} -> {continue, {error, Index - node_size(Node@1)}} end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 1218). -spec try_map_node(node_(JCY), fun((JCY) -> {ok, JDA} | {error, JDB})) -> {ok, node_(JDA)} | {error, JDB}. try_map_node(Node, F) -> case Node of {one, W} -> gleam@result:map(F(W), fun(W@1) -> {one, W@1} end); {two, W@2, X} -> gleam@result:'try'( F(W@2), fun(W@3) -> gleam@result:map(F(X), fun(X@1) -> {two, W@3, X@1} end) end ); {three, W@4, X@2, Y} -> gleam@result:'try'( F(W@4), fun(W@5) -> gleam@result:'try'( F(X@2), fun(X@3) -> gleam@result:map( F(Y), fun(Y@1) -> {three, W@5, X@3, Y@1} end ) end ) end ); {four, W@6, X@4, Y@2, Z} -> gleam@result:'try'( F(W@6), fun(W@7) -> gleam@result:'try'( F(X@4), fun(X@5) -> gleam@result:'try'( F(Y@2), fun(Y@3) -> gleam@result:map( F(Z), fun(Z@1) -> {four, W@7, X@5, Y@3, Z@1} end ) end ) end ) end ) end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 1213). -spec try_map_root( shine_tree(node_(JCQ)), fun((JCQ) -> {ok, JCT} | {error, JCU}) ) -> {ok, shine_tree(node_(JCT))} | {error, JCU}. try_map_root(Root, F) -> try_map(Root, fun(Node) -> try_map_node(Node, F) end). -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 1194). -spec try_map(shine_tree(JCH), fun((JCH) -> {ok, JCJ} | {error, JCK})) -> {ok, shine_tree(JCJ)} | {error, JCK}. try_map(Tree, F) -> case Tree of empty -> {ok, empty}; {single, U} -> gleam@result:map(F(U), fun(U@1) -> {single, U@1} end); {deep, Count, Pf, Root, Sf} -> gleam@result:'try'( try_map_node(Pf, F), fun(Pf@1) -> gleam@result:'try'( try_map_root(Root, F), fun(Root@1) -> gleam@result:map( try_map_node(Sf, F), fun(Sf@1) -> {deep, Count, Pf@1, Root@1, Sf@1} end ) end ) end ) end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 758). -spec do_fold_r_until( shine_tree(IYL), IYO, fun((IYO, IYL) -> gleam@list:continue_or_stop(IYO)) ) -> gleam@list:continue_or_stop(IYO). do_fold_r_until(Tree, V, F) -> case Tree of empty -> {continue, V}; {single, U} -> F(V, U); {deep, _, Pf, Root, Sf} -> try_continue( do_fold_node_r_until(Sf, V, F), fun(V@1) -> try_continue( (do_fold_r_until( Root, V@1, fun(V@2, Node) -> do_fold_node_r_until(Node, V@2, F) end )), fun(V@3) -> do_fold_node_r_until(Pf, V@3, F) end ) end ) end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 732). -spec fold_r_until( shine_tree(IYA), IYD, fun((IYD, IYA) -> gleam@list:continue_or_stop(IYD)) ) -> IYD. fold_r_until(Tree, V, F) -> _pipe = do_fold_r_until(Tree, V, F), unwrap_fold_until(_pipe). -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 1177). -spec try_foldr( shine_tree(JBY), JCB, fun((JCB, JBY) -> {ok, JCB} | {error, JCC}) ) -> {ok, JCB} | {error, JCC}. try_foldr(Tree, Acc, F) -> fold_r_until( Tree, {ok, Acc}, fun(Acc@1, U) -> {ok, Acc@2} = case Acc@1 of {ok, _} -> Acc@1; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, value => _assert_fail, module => <<"shine_tree"/utf8>>, function => <<"try_foldr"/utf8>>, line => 1183}) end, case F(Acc@2, U) of {ok, Acc@3} -> {continue, {ok, Acc@3}}; {error, Err} -> {stop, {error, Err}} end end ). -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 647). -spec any_rec(shine_tree(IWY), fun((IWY) -> boolean())) -> boolean(). any_rec(Tree, F) -> any(Tree, F). -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 626). -spec any(shine_tree(IWS), fun((IWS) -> boolean())) -> boolean(). any(Tree, F) -> case Tree of empty -> false; {single, U} -> F(U); {deep, _, Pf, Root, Sf} -> case {any_node(Pf, F), any_node(Sf, F)} of {false, false} -> any_rec(Root, fun(_capture) -> any_node(_capture, F) end); {_, _} -> true end end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 652). -spec contains(shine_tree(IXB), IXB) -> boolean(). contains(Tree, U) -> any(Tree, fun(V) -> V =:= U end). -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 583). -spec all(shine_tree(IWM), fun((IWM) -> boolean())) -> boolean(). all(Tree, F) -> case Tree of empty -> true; {single, U} -> F(U); {deep, _, Pf, Root, Sf} -> case {all_node(Pf, F), all_node(Sf, F)} of {true, true} -> all(Root, fun(_capture) -> all_node(_capture, F) end); {_, _} -> false end end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 533). -spec reverse_rec(shine_tree(node_(IWA))) -> shine_tree(node_(IWA)). reverse_rec(Tree) -> _pipe = Tree, _pipe@1 = map(_pipe, fun reverse_node/1), reverse(_pipe@1). -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 525). -spec reverse(shine_tree(IVX)) -> shine_tree(IVX). reverse(Tree) -> case Tree of {deep, Count, Pf, Root, Sf} -> {deep, Count, begin _pipe = Sf, reverse_node(_pipe) end, begin _pipe@1 = Root, reverse_rec(_pipe@1) end, begin _pipe@2 = Pf, reverse_node(_pipe@2) end}; Tree@1 -> Tree@1 end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 513). -spec append_rec(shine_tree(node_(IVN)), shine_tree(node_(IVN))) -> shine_tree(node_(IVN)). append_rec(Tree_1, Tree_2) -> _pipe = Tree_1, append(_pipe, Tree_2). -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 497). -spec append(shine_tree(IVJ), shine_tree(IVJ)) -> shine_tree(IVJ). append(Tree_1, Tree_2) -> case {Tree_1, Tree_2} of {T1, empty} -> T1; {empty, T2} -> T2; {T1@1, {single, A}} -> _pipe = T1@1, push(_pipe, A); {{single, A@1}, T2@1} -> _pipe@1 = T2@1, unshift(_pipe@1, A@1); {{deep, Count1, Pf1, Root1, Sf1}, {deep, Count2, Pf2, Root2, Sf2}} -> {deep, Count1 + Count2, Pf1, begin _pipe@2 = Root1, _pipe@3 = push(_pipe@2, Sf1), append_rec( _pipe@3, begin _pipe@4 = Root2, unshift(_pipe@4, Pf2) end ) end, Sf2} end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 493). -spec prepend(shine_tree(IVF), shine_tree(IVF)) -> shine_tree(IVF). prepend(Tree_1, Tree_2) -> append(Tree_2, Tree_1). -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 517). -spec concat(list(shine_tree(IVT))) -> shine_tree(IVT). concat(Trees) -> case Trees of [] -> empty; [A] -> A; [A@1 | Rest] -> append(A@1, concat(Rest)) end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 743). -spec do_fold_l_until( shine_tree(IYF), IYI, fun((IYI, IYF) -> gleam@list:continue_or_stop(IYI)) ) -> gleam@list:continue_or_stop(IYI). do_fold_l_until(Tree, V, F) -> case Tree of empty -> {continue, V}; {single, U} -> F(V, U); {deep, _, Pf, Root, Sf} -> try_continue( do_fold_node_l_until(Pf, V, F), fun(V@1) -> try_continue( (do_fold_l_until( Root, V@1, fun(V@2, Node) -> do_fold_node_l_until(Node, V@2, F) end )), fun(V@3) -> do_fold_node_l_until(Sf, V@3, F) end ) end ) end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 717). -spec fold_l_until( shine_tree(IXV), IXY, fun((IXY, IXV) -> gleam@list:continue_or_stop(IXY)) ) -> IXY. fold_l_until(Tree, V, F) -> _pipe = do_fold_l_until(Tree, V, F), unwrap_fold_until(_pipe). -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 1159). -spec try_foldl( shine_tree(JBP), JBS, fun((JBS, JBP) -> {ok, JBS} | {error, JBT}) ) -> {ok, JBS} | {error, JBT}. try_foldl(Tree, Acc, F) -> fold_l_until( Tree, {ok, Acc}, fun(Acc@1, U) -> {ok, Acc@2} = case Acc@1 of {ok, _} -> Acc@1; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, value => _assert_fail, module => <<"shine_tree"/utf8>>, function => <<"try_foldl"/utf8>>, line => 1165}) end, case F(Acc@2, U) of {ok, U@1} -> {continue, {ok, U@1}}; {error, Err} -> {stop, {error, Err}} end end ). -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 393). -spec find(shine_tree(IUG), fun((IUG) -> boolean())) -> {ok, IUG} | {error, nil}. find(Tree, F) -> _pipe = (fold_l_until(Tree, none, fun(_, Item) -> case F(Item) of true -> {stop, {some, Item}}; false -> {continue, none} end end)), gleam@option:to_result(_pipe, nil). -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 417). -spec find_map(shine_tree(IUJ), fun((IUJ) -> {ok, IUL} | {error, any()})) -> {ok, IUL} | {error, nil}. find_map(Tree, F) -> _pipe = (fold_l_until(Tree, none, fun(_, Item) -> case F(Item) of {ok, Val} -> {stop, {some, Val}}; _ -> {continue, none} end end)), gleam@option:to_result(_pipe, nil). -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 1123). -spec do_get_root(shine_tree(node_(JBG)), integer()) -> {ok, JBG} | {error, nil}. do_get_root(Node, Index) -> _pipe = (fold_l_until( Node, {error, Index}, fun(Index@1, Node@1) -> {error, Index@2} = case Index@1 of {error, _} -> Index@1; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, value => _assert_fail, module => <<"shine_tree"/utf8>>, function => <<"do_get_root"/utf8>>, line => 1126}) end, get_node(Index@2, Node@1) end )), gleam@result:replace_error(_pipe, nil). -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 1090). -spec get(shine_tree(JBC), integer()) -> {ok, JBC} | {error, nil}. get(Tree, Index) -> case {Tree, Index} of {empty, _} -> {error, nil}; {{single, U}, 0} -> {ok, U}; {{single, _}, _} -> {error, nil}; {{deep, Count, _, _, _}, Index@1} when (Index@1 >= Count) orelse (Index@1 < 0) -> {error, nil}; {{deep, _, {one, U@1}, _, _}, 0} -> {ok, U@1}; {{deep, _, {two, U@2, _}, _, _}, 0} -> {ok, U@2}; {{deep, _, {three, U@3, _, _}, _, _}, 0} -> {ok, U@3}; {{deep, _, {four, U@4, _, _, _}, _, _}, 0} -> {ok, U@4}; {{deep, _, {two, _, V}, _, _}, 1} -> {ok, V}; {{deep, _, {three, _, V@1, _}, _, _}, 1} -> {ok, V@1}; {{deep, _, {four, _, V@2, _, _}, _, _}, 1} -> {ok, V@2}; {{deep, _, {three, _, _, W}, _, _}, 2} -> {ok, W}; {{deep, _, {four, _, _, W@1, _}, _, _}, 2} -> {ok, W@1}; {{deep, _, {four, _, _, _, X}, _, _}, 3} -> {ok, X}; {{deep, Count@1, _, _, {one, U@5}}, Index@2} when Index@2 =:= (Count@1 - 1) -> {ok, U@5}; {{deep, Count@2, _, _, {two, _, U@6}}, Index@3} when Index@3 =:= (Count@2 - 1) -> {ok, U@6}; {{deep, Count@3, _, _, {three, _, _, U@7}}, Index@4} when Index@4 =:= (Count@3 - 1) -> {ok, U@7}; {{deep, Count@4, _, _, {four, _, _, _, U@8}}, Index@5} when Index@5 =:= (Count@4 - 1) -> {ok, U@8}; {{deep, Count@5, _, _, {two, V@3, _}}, Index@6} when Index@6 =:= (Count@5 - 2) -> {ok, V@3}; {{deep, Count@6, _, _, {three, _, V@4, _}}, Index@7} when Index@7 =:= (Count@6 - 2) -> {ok, V@4}; {{deep, Count@7, _, _, {four, _, _, V@5, _}}, Index@8} when Index@8 =:= (Count@7 - 2) -> {ok, V@5}; {{deep, Count@8, _, _, {three, W@2, _, _}}, Index@9} when Index@9 =:= (Count@8 - 3) -> {ok, W@2}; {{deep, Count@9, _, _, {four, _, W@3, _, _}}, Index@10} when Index@10 =:= (Count@9 - 3) -> {ok, W@3}; {{deep, Count@10, _, _, {four, X@1, _, _, _}}, Index@11} when Index@11 =:= (Count@10 - 4) -> {ok, X@1}; {{deep, _, Pf, Root, _}, Index@12} -> Index@13 = Index@12 - node_size(Pf), do_get_root(Root, Index@13) end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 453). -spec do_from_list_reverse(list(IUX)) -> shine_tree(IUX). do_from_list_reverse(Value) -> case Value of [] -> empty; [A] -> {single, A}; [A@1, B] -> {deep, 2, {one, B}, empty, {one, A@1}}; [A@2, B@1, C] -> {deep, 3, {two, C, B@1}, empty, {one, A@2}}; [A@3, B@2, C@1, D] -> {deep, 4, {two, D, C@1}, empty, {two, B@2, A@3}}; [A@4, B@3, C@2, D@1, E] -> {deep, 5, {three, E, D@1, C@2}, empty, {two, B@3, A@4}}; [A@5, B@4, C@3, D@2, E@1, F] -> {deep, 6, {three, F, E@1, D@2}, empty, {three, C@3, B@4, A@5}}; [A@6, B@5, C@4, D@3, E@2, F@1, G] -> {deep, 7, {four, G, F@1, E@2, D@3}, empty, {three, C@4, B@5, A@6}}; [A@7, B@6, C@5, D@4, E@3, F@2, G@1, H] -> {deep, 8, {four, H, G@1, F@2, E@3}, empty, {four, D@4, C@5, B@6, A@7}}; [A@8, B@7, C@6, D@5, E@4, F@3, G@2, H@1, I] -> {deep, 9, {four, I, H@1, G@2, F@3}, {single, {one, E@4}}, {four, D@5, C@6, B@7, A@8}}; [A@9, B@8, C@7, D@6, E@5, F@4, G@3, H@2, I@1, J] -> {deep, 10, {four, J, I@1, H@2, G@3}, {single, {two, F@4, E@5}}, {four, D@6, C@7, B@8, A@9}}; [A@10, B@9, C@8, D@7, E@6, F@5, G@4, H@3, I@2, J@1, K] -> {deep, 11, {four, K, J@1, I@2, H@3}, {single, {three, G@4, F@5, E@6}}, {four, D@7, C@8, B@9, A@10}}; [A@11, B@10, C@9, D@8, E@7, F@6, G@5, H@4, I@3, J@2, K@1, L] -> {deep, 12, {four, L, K@1, J@2, I@3}, {single, {four, H@4, G@5, F@6, E@7}}, {four, D@8, C@9, B@10, A@11}}; [A@12, B@11, C@10, D@9 | Rest] -> Tail = {four, D@9, C@10, B@11, A@12}, {Head, Nodes, Count} = do_chunk_values_reverse(Rest, [], 4), {deep, Count, Head, do_from_list(Nodes), Tail} end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 358). -spec do_from_list(list(IUD)) -> shine_tree(IUD). do_from_list(Values) -> case Values of [] -> empty; [A] -> {single, A}; [A@1, B] -> {deep, 2, {one, A@1}, empty, {one, B}}; [A@2, B@1, C] -> {deep, 3, {two, A@2, B@1}, empty, {one, C}}; [A@3, B@2, C@1, D] -> {deep, 4, {two, A@3, B@2}, empty, {two, C@1, D}}; [A@4, B@3, C@2, D@1, E] -> {deep, 5, {three, A@4, B@3, C@2}, empty, {two, D@1, E}}; [A@5, B@4, C@3, D@2, E@1, F] -> {deep, 6, {three, A@5, B@4, C@3}, empty, {three, D@2, E@1, F}}; [A@6, B@5, C@4, D@3, E@2, F@1, G] -> {deep, 7, {four, A@6, B@5, C@4, D@3}, empty, {three, E@2, F@1, G}}; [A@7, B@6, C@5, D@4, E@3, F@2, G@1, H] -> {deep, 8, {four, A@7, B@6, C@5, D@4}, empty, {four, E@3, F@2, G@1, H}}; [A@8, B@7, C@6, D@5, E@4, F@3, G@2, H@1, I] -> {deep, 9, {four, A@8, B@7, C@6, D@5}, {single, {one, E@4}}, {four, F@3, G@2, H@1, I}}; [A@9, B@8, C@7, D@6, E@5, F@4, G@3, H@2, I@1, J] -> {deep, 10, {four, A@9, B@8, C@7, D@6}, {single, {two, E@5, F@4}}, {four, G@3, H@2, I@1, J}}; [A@10, B@9, C@8, D@7, E@6, F@5, G@4, H@3, I@2, J@1, K] -> {deep, 11, {four, A@10, B@9, C@8, D@7}, {single, {three, E@6, F@5, G@4}}, {four, H@3, I@2, J@1, K}}; [A@11, B@10, C@9, D@8, E@7, F@6, G@5, H@4, I@3, J@2, K@1, L] -> {deep, 12, {four, A@11, B@10, C@9, D@8}, {single, {four, E@7, F@6, G@5, H@4}}, {four, I@3, J@2, K@1, L}}; [A@12, B@11, C@10, D@9 | Rest] -> {Tail, Rest@1, Count} = do_chunk_values(Rest, [], 4), {deep, Count, {four, A@12, B@11, C@10, D@9}, do_from_list_reverse(Rest@1), Tail} end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 354). -spec from_list(list(IUA)) -> shine_tree(IUA). from_list(Values) -> do_from_list(Values). -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 909). -spec do_deep_range(integer(), integer(), list(node_(integer()))) -> shine_tree(node_(integer())). do_deep_range(Start, Finish, Acc) -> case Finish - Start of 0 -> _pipe = [{one, Start} | Acc], do_from_list_reverse(_pipe); 1 -> _pipe@1 = [range_2(Start) | Acc], do_from_list_reverse(_pipe@1); 2 -> _pipe@2 = [range_3(Start) | Acc], do_from_list_reverse(_pipe@2); 3 -> _pipe@3 = [range_4(Start) | Acc], do_from_list_reverse(_pipe@3); 4 -> _pipe@4 = [{one, Finish}, range_4(Finish - 4) | Acc], do_from_list_reverse(_pipe@4); _ -> do_deep_range(Start + 4, Finish, [range_4(Start) | Acc]) end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 837). -spec range(integer(), integer()) -> shine_tree(integer()). range(Start, Finish) -> case Finish - Start of Val when Val < 0 -> _pipe = range(Finish, Start), reverse(_pipe); 0 -> {single, Start}; 1 -> {deep, 2, {one, Start}, empty, {one, Finish}}; 2 -> {deep, 3, range_2(Start), empty, {one, Finish}}; 3 -> {deep, 4, {two, Start, Start + 1}, empty, {two, Start + 2, Finish}}; 4 -> {deep, 5, {three, Start, Start + 1, Start + 2}, empty, {two, Start + 3, Finish}}; 5 -> {deep, 6, {three, Start, Start + 1, Start + 2}, empty, {three, Start + 3, Start + 4, Finish}}; 6 -> {deep, 7, {four, Start, Start + 1, Start + 2, Start + 3}, empty, {three, Start + 4, Start + 5, Finish}}; 7 -> {deep, 8, {four, Start, Start + 1, Start + 2, Start + 3}, empty, {four, Start + 4, Start + 5, Start + 6, Finish}}; 8 -> {deep, 9, {four, Start, Start + 1, Start + 2, Start + 3}, {single, {one, Start + 4}}, {four, Start + 5, Start + 6, Start + 7, Finish}}; 9 -> {deep, 10, {four, Start, Start + 1, Start + 2, Start + 3}, {single, {two, Start + 4, Start + 5}}, {four, Start + 6, Start + 7, Start + 8, Finish}}; 10 -> {deep, 11, {four, Start, Start + 1, Start + 2, Start + 3}, {single, {three, Start + 4, Start + 5, Start + 6}}, {four, Start + 7, Start + 8, Start + 9, Finish}}; 11 -> {deep, 12, {four, Start, Start + 1, Start + 2, Start + 3}, {single, {four, Start + 4, Start + 5, Start + 6, Start + 7}}, {four, Start + 8, Start + 9, Start + 10, Finish}}; N -> {deep, N + 1, range_4(Start), do_deep_range(Start + 4, Finish - 4, []), range_4(Finish - 3)} end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 280). -spec shift(shine_tree(ITM)) -> {ok, {ITM, shine_tree(ITM)}} | {error, nil}. shift(Tree) -> case Tree of empty -> {error, nil}; {single, U} -> {ok, {U, empty}}; {deep, _, {one, U@1}, empty, {one, V}} -> {ok, {U@1, {single, V}}}; {deep, Count, {one, U@2}, empty, {two, V@1, W}} -> {ok, {U@2, {deep, Count - 1, {one, V@1}, empty, {one, W}}}}; {deep, Count@1, {one, U@3}, empty, {three, V@2, W@1, X}} -> {ok, {U@3, {deep, Count@1 - 1, {two, V@2, W@1}, empty, {one, X}}}}; {deep, Count@2, {one, U@4}, empty, {four, V@3, W@2, X@1, Y}} -> {ok, {U@4, {deep, Count@2 - 1, {two, V@3, W@2}, empty, {two, X@1, Y}}}}; {deep, Count@3, {one, U@5}, Root, Sf} -> _assert_subject = shift(Root), {ok, {Pf, Root@1}} = case _assert_subject of {ok, {_, _}} -> _assert_subject; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, value => _assert_fail, module => <<"shine_tree"/utf8>>, function => <<"shift"/utf8>>, line => 292}) end, {ok, {U@5, {deep, Count@3 - 1, Pf, Root@1, Sf}}}; {deep, Count@4, Pf@1, Root@2, Sf@1} -> _assert_subject@1 = shift_node(Pf@1), {ok, {U@6, Pf@2}} = case _assert_subject@1 of {ok, {_, _}} -> _assert_subject@1; _assert_fail@1 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, value => _assert_fail@1, module => <<"shine_tree"/utf8>>, function => <<"shift"/utf8>>, line => 296}) end, {ok, {U@6, {deep, Count@4 - 1, Pf@2, Root@2, Sf@1}}} end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 952). -spec equals(shine_tree(IZP), shine_tree(IZP)) -> boolean(). equals(A, B) -> case {A, B} of {A@1, B@1} when A@1 =:= B@1 -> true; {A@2, B@2} -> case {shift(A@2), shift(B@2)} of {{ok, {Item_a, A@3}}, {ok, {Item_b, B@3}}} when Item_a =:= Item_b -> equals(A@3, B@3); {_, _} -> false end end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 231). -spec pop(shine_tree(ITE)) -> {ok, {ITE, shine_tree(ITE)}} | {error, nil}. pop(Tree) -> case Tree of empty -> {error, nil}; {single, U} -> {ok, {U, empty}}; {deep, _, {one, V}, empty, {one, U@1}} -> {ok, {U@1, {single, V}}}; {deep, Count, {two, V@1, W}, empty, {one, U@2}} -> {ok, {U@2, {deep, Count - 1, {one, V@1}, empty, {one, W}}}}; {deep, Count@1, {three, V@2, W@1, X}, empty, {one, U@3}} -> {ok, {U@3, {deep, Count@1 - 1, {two, V@2, W@1}, empty, {one, X}}}}; {deep, Count@2, {four, V@3, W@2, X@1, Y}, empty, {one, U@4}} -> {ok, {U@4, {deep, Count@2 - 1, {two, V@3, W@2}, empty, {two, X@1, Y}}}}; {deep, Count@3, Pf, Root, {one, U@5}} -> _assert_subject = pop(Root), {ok, {Sf, Root@1}} = case _assert_subject of {ok, {_, _}} -> _assert_subject; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, value => _assert_fail, module => <<"shine_tree"/utf8>>, function => <<"pop"/utf8>>, line => 243}) end, {ok, {U@5, {deep, Count@3 - 1, Pf, Root@1, Sf}}}; {deep, Count@4, Pf@1, Root@2, Sf@1} -> _assert_subject@1 = pop_node(Sf@1), {ok, {U@6, Sf@2}} = case _assert_subject@1 of {ok, {_, _}} -> _assert_subject@1; _assert_fail@1 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, value => _assert_fail@1, module => <<"shine_tree"/utf8>>, function => <<"pop"/utf8>>, line => 247}) end, {ok, {U@6, {deep, Count@4 - 1, Pf@1, Root@2, Sf@2}}} end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 199). -spec unshift(shine_tree(ITB), ITB) -> shine_tree(ITB). unshift(Tree, Value) -> case Tree of empty -> {single, Value}; {single, V} -> {deep, 2, {one, Value}, empty, {one, V}}; {deep, Count, {one, V@1}, Root, Sf} -> {deep, Count + 1, {two, Value, V@1}, Root, Sf}; {deep, Count@1, {two, V@2, W}, Root@1, Sf@1} -> {deep, Count@1 + 1, {three, Value, V@2, W}, Root@1, Sf@1}; {deep, Count@2, {three, V@3, W@1, X}, Root@2, Sf@2} -> {deep, Count@2 + 1, {four, Value, V@3, W@1, X}, Root@2, Sf@2}; {deep, Count@3, Pf, Root@3, Sf@3} -> {deep, Count@3 + 1, {one, Value}, unshift(Root@3, Pf), Sf@3} end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 176). -spec push(shine_tree(ISY), ISY) -> shine_tree(ISY). push(Tree, Value) -> case Tree of empty -> {single, Value}; {single, V} -> {deep, 2, {one, V}, empty, {one, Value}}; {deep, Count, Pf, Root, {one, V@1}} -> {deep, Count + 1, Pf, Root, {two, V@1, Value}}; {deep, Count@1, Pf@1, Root@1, {two, V@2, W}} -> {deep, Count@1 + 1, Pf@1, Root@1, {three, V@2, W, Value}}; {deep, Count@2, Pf@2, Root@2, {three, V@3, W@1, X}} -> {deep, Count@2 + 1, Pf@2, Root@2, {four, V@3, W@1, X, Value}}; {deep, Count@3, Pf@3, Root@3, Sf} -> {deep, Count@3 + 1, Pf@3, push(Root@3, Sf), {one, Value}} end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 164). -spec map_root(shine_tree(node_(ISS)), fun((ISS) -> ISV)) -> shine_tree(node_(ISV)). map_root(Root, F) -> map(Root, fun(Node) -> map_node(Node, F) end). -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 142). -spec map(shine_tree(ISK), fun((ISK) -> ISM)) -> shine_tree(ISM). map(Tree, F) -> case Tree of empty -> empty; {single, U} -> {single, F(U)}; {deep, Count, Pf, Root, Sf} -> Pf@1 = map_node(Pf, F), Root@1 = map_root(Root, F), Sf@1 = map_node(Sf, F), {deep, Count, Pf@1, Root@1, Sf@1} end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 126). -spec fold_r_root(ISG, shine_tree(node_(ISH)), fun((ISG, ISH) -> ISG)) -> ISG. fold_r_root(Acc, Root, F) -> fold_r(Root, Acc, fun(Acc@1, Node) -> fold_r_node(Acc@1, Node, F) end). -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 92). -spec fold_r(shine_tree(IRY), any(), fun((ISB, IRY) -> ISB)) -> ISB. fold_r(Tree, V, F) -> case Tree of empty -> V; {single, U} -> F(V, U); {deep, _, Pf, Root, Sf} -> _pipe = V, _pipe@1 = fold_r_node(_pipe, Sf, F), _pipe@2 = fold_r_root(_pipe@1, Root, F), fold_r_node(_pipe@2, Pf, F) end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 322). -spec filter(shine_tree(ITU), fun((ITU) -> boolean())) -> shine_tree(ITU). filter(Tree, F) -> _pipe = (fold_r(Tree, [], fun(Acc, U) -> case F(U) of true -> [U | Acc]; false -> Acc end end)), do_from_list(_pipe). -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 341). -spec to_list(shine_tree(ITX)) -> list(ITX). to_list(Tree) -> fold_r(Tree, [], fun(Acc, U) -> [U | Acc] end). -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 71). -spec fold_l_root(IRU, shine_tree(node_(IRV)), fun((IRU, IRV) -> IRU)) -> IRU. fold_l_root(Acc, Root, F) -> fold_l(Root, Acc, fun(Acc@1, Node) -> fold_l_node(Acc@1, Node, F) end). -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 37). -spec fold_l(shine_tree(IRM), any(), fun((IRP, IRM) -> IRP)) -> IRP. fold_l(Tree, V, F) -> case Tree of empty -> V; {single, U} -> F(V, U); {deep, _, Pf, Root, Sf} -> _pipe = V, _pipe@1 = fold_l_node(_pipe, Pf, F), _pipe@2 = fold_l_root(_pipe@1, Root, F), fold_l_node(_pipe@2, Sf, F) end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 668). -spec count(shine_tree(IXF), fun((IXF) -> boolean())) -> integer(). count(Tree, F) -> fold_l(Tree, 0, fun(Acc, U) -> case F(U) of true -> Acc + 1; false -> Acc end end). -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 683). -spec each(shine_tree(IXL), fun((IXL) -> any())) -> nil. each(Tree, F) -> fold_l( Tree, nil, fun(_, Item) -> F(Item), nil end ). -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 691). -spec filter_map(shine_tree(IXO), fun((IXO) -> {ok, IXQ} | {error, any()})) -> shine_tree(IXQ). filter_map(Tree, F) -> _pipe = (fold_l(Tree, [], fun(Acc, Item) -> case F(Item) of {ok, B} -> [B | Acc]; _ -> Acc end end)), do_from_list_reverse(_pipe). -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 979). -spec partition(shine_tree(IZW), IZW, fun((IZW, IZW) -> gleam@order:order())) -> {list(IZW), list(IZW)}. partition(Tree, Pivot, Compare) -> fold_l( Tree, {[], []}, fun(_use0, Item) -> {Left, Right} = _use0, case Compare(Item, Pivot) of gt -> {Left, [Item | Right]}; _ -> {[Item | Left], Right} end end ). -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 964). -spec sort(shine_tree(IZT), fun((IZT, IZT) -> gleam@order:order())) -> shine_tree(IZT). sort(Tree, Compare) -> case Tree of empty -> empty; {single, U} -> {single, U}; _ -> _assert_subject = shift(Tree), {ok, {Pivot, Tree@1}} = case _assert_subject of {ok, {_, _}} -> _assert_subject; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, value => _assert_fail, module => <<"shine_tree"/utf8>>, function => <<"sort"/utf8>>, line => 969}) end, {Left, Right} = partition(Tree@1, Pivot, Compare), Left@1 = gleam@list:sort(Left, Compare), Right@1 = [Pivot | gleam@list:sort(Right, Compare)], _pipe = lists:append(Left@1, Right@1), from_list(_pipe) end. -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 1080). -spec do_group_by( gleam@dict:dict(JAU, list(JAV)), shine_tree(node_(JAV)), fun((JAV) -> JAU) ) -> gleam@dict:dict(JAU, list(JAV)). do_group_by(Dict, Tree, F) -> fold_l( Tree, Dict, fun(Final_dict, Item) -> do_group_by_node(Final_dict, Item, F) end ). -file("/home/jtenner/Projects/shine_tree/src/shine_tree.gleam", 1019). -spec group(shine_tree(JAH), fun((JAH) -> JAJ)) -> gleam@dict:dict(JAJ, shine_tree(JAH)). group(Tree, F) -> case Tree of empty -> maps:new(); {single, U} -> gleam@dict:insert(maps:new(), F(U), {single, U}); {deep, _, Pf, Root, Sf} -> _pipe = maps:new(), _pipe@1 = do_group_by_node(_pipe, Pf, F), _pipe@2 = do_group_by(_pipe@1, Root, F), _pipe@3 = do_group_by_node(_pipe@2, Sf, F), gleam@dict:map_values( _pipe@3, fun(_, Value) -> from_list(Value) end ) end.