-module(fp2@non_empty_list). -compile(no_auto_import). -export(['of'/1, append/2, append_list/2, to_list/1, prepend/2, prepend_list/2]). -export_type([non_empty_list/1]). -type non_empty_list(EZB) :: {non_empty_list, EZB, list(EZB)}. -spec 'of'(EZE) -> non_empty_list(EZE). 'of'(Head) -> {non_empty_list, Head, []}. -spec append(non_empty_list(EZG), EZG) -> non_empty_list(EZG). append(Init, End) -> {non_empty_list, erlang:element(2, Init), gleam@list:append(erlang:element(3, Init), [End])}. -spec append_list(list(EZJ), EZJ) -> non_empty_list(EZJ). append_list(Init, End) -> case Init of [] -> {non_empty_list, End, []}; [X | Xs] -> {non_empty_list, X, gleam@list:append(Xs, [End])} end. -spec to_list(non_empty_list(EZM)) -> list(EZM). to_list(It) -> gleam@list:append([erlang:element(2, It)], erlang:element(3, It)). -spec prepend(non_empty_list(EZP), EZP) -> non_empty_list(EZP). prepend(Tail, Head) -> {non_empty_list, Head, gleam@list:append([erlang:element(2, Tail)], erlang:element(3, Tail))}. -spec prepend_list(list(EZS), EZS) -> non_empty_list(EZS). prepend_list(Tail, Head) -> {non_empty_list, Head, Tail}.