-module(zip_list). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/zip_list.gleam"). -export([new/3, singleton/1, from_list/1, from_list_by/2, to_list/1, first/1, jump/2, last/1, next_try/1, next/1, forward/2, next_wrap/1, previous_try/1, previous/1, backwards/2, previous_wrap/1, append_next/2, append_previous/2, current_map/2, filter/2, index_map/2, map/2, prepend_next/2, prepend_previous/2, remove_try/1, remove/1, remove_backwards/1, replace/2, get_all_next/1, get_all_previous/1, current/1, index/1, get_next/1, get_previous/1, is_first/1, is_last/1, length/1]). -export_type([zip_list/1]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. -opaque zip_list(KDR) :: {zip_list, list(KDR), KDR, list(KDR)}. -file("src/zip_list.gleam", 19). ?DOC( " Create a new ZipList\n" "\n" " ## Examples\n" " ```gleam\n" " let numbers = new([1, 2], 3, [4, 5])\n" " current(numbers)\n" " // => 3\n" " ```\n" ). -spec new(list(KDS), KDS, list(KDS)) -> zip_list(KDS). new(Previous, Current, Next) -> {zip_list, Previous, Current, Next}. -file("src/zip_list.gleam", 33). ?DOC( " Create a new ZipList with a single element\n" "\n" " ## Examples\n" " ```gleam\n" " singleton(1) == new([], 1, [])\n" " ```\n" ). -spec singleton(KDW) -> zip_list(KDW). singleton(Current) -> {zip_list, [], Current, []}. -file("src/zip_list.gleam", 45). ?DOC( " Create a new ZipList from a list\n" " Returns `Error(Nil)` if the list is empty\n" "\n" " ## Examples\n" " ```gleam\n" " from_list([1, 2, 3, 4, 5]) == Ok(new([], 1, [2, 3, 4, 5]))\n" " from_list([]) == Error(Nil)\n" " ```\n" ). -spec from_list(list(KDY)) -> {ok, zip_list(KDY)} | {error, nil}. from_list(List) -> case List of [] -> {error, nil}; [Head | Tail] -> {ok, {zip_list, [], Head, Tail}} end. -file("src/zip_list.gleam", 65). -spec from_list_by_helper(list(KEI), fun((KEI) -> boolean()), list(KEI)) -> {ok, zip_list(KEI)} | {error, nil}. from_list_by_helper(Previous, Predicate, Remaining) -> case Remaining of [] -> {error, nil}; [Head | Tail] -> case Predicate(Head) of true -> {ok, {zip_list, Previous, Head, Tail}}; false -> from_list_by_helper( lists:append(Previous, [Head]), Predicate, Tail ) end end. -file("src/zip_list.gleam", 58). ?DOC( " Create a new ZipList from a list, setting the current element to the first element that satisfies the predicate///\n" " ## Examples\n" " ```gleam\n" " from_list_by([1, 2, 3, 4, 5], fn(x) { x == 3 }) == Ok(new([1, 2], 3, [4, 5]))\n" " from_list_by([1, 2, 3, 4, 5], fn(x) { x == 6 }) == Error(Nil)\n" " ```\n" ). -spec from_list_by(list(KED), fun((KED) -> boolean())) -> {ok, zip_list(KED)} | {error, nil}. from_list_by(List, Predicate) -> from_list_by_helper([], Predicate, List). -file("src/zip_list.gleam", 90). ?DOC( " Convert a ZipList to a list\n" "\n" " ## Examples\n" " ```gleam\n" " to_list(new([1, 2], 3, [4, 5]))\n" " // => [1, 2, 3, 4, 5]\n" " ```\n" ). -spec to_list(zip_list(KEO)) -> list(KEO). to_list(Zip_list) -> lists:append( erlang:element(2, Zip_list), [erlang:element(3, Zip_list) | erlang:element(4, Zip_list)] ). -file("src/zip_list.gleam", 127). ?DOC( " Move the cursor to the first element\n" "\n" " ## Examples\n" " ```gleam\n" " let numbers = new([1, 2], 3, [4, 5])\n" " first(numbers) == new([], 1, [2, 3, 4, 5])\n" " ```\n" " ```gleam\n" " let numbers = new([], 1, [2, 3, 4, 5])\n" " first(numbers) == new([], 1, [2, 3, 4, 5])\n" " ```\n" ). -spec first(zip_list(KEU)) -> zip_list(KEU). first(Zip_list) -> case erlang:element(2, Zip_list) of [] -> Zip_list; [Head | Tail] -> {zip_list, [], Head, lists:append( Tail, [erlang:element(3, Zip_list) | erlang:element(4, Zip_list)] )} end. -file("src/zip_list.gleam", 170). ?DOC( " Move the cursor to the Nth element\n" "\n" " ## Examples\n" " ```gleam\n" " let numbers = new([1, 2], 3, [4, 5])\n" " jump(numbers, 1) == new([1], 2, [3, 4, 5])\n" " ```\n" " ```gleam\n" " let numbers = new([1, 2], 3, [4, 5])\n" " jump(numbers, 5) == new([1, 2, 3, 4], 5, [])\n" " ```\n" ). -spec jump(zip_list(KFA), integer()) -> zip_list(KFA). jump(Zip_list, Index) -> {First, Second} = begin _pipe = Zip_list, _pipe@1 = to_list(_pipe), gleam@list:split(_pipe@1, Index) end, {Previous, Current, Next} = case {lists:reverse(First), Second} of {[], []} -> {erlang:element(2, Zip_list), erlang:element(3, Zip_list), erlang:element(4, Zip_list)}; {_, [Head | Tail]} -> {First, Head, Tail}; {[Head@1 | Tail@1], []} -> {lists:reverse(Tail@1), Head@1, Second} end, {zip_list, Previous, Current, Next}. -file("src/zip_list.gleam", 196). ?DOC( " Move the cursor to the last element\n" "\n" " ## Examples\n" " ```gleam\n" " let numbers = new([1, 2], 3, [4, 5])\n" " last(numbers) == new([1, 2, 3, 4], 5, [])\n" " ```\n" " ```gleam\n" " let numbers = new([1, 2, 3, 4], 5, [])\n" " last(numbers) == new([1, 2, 3, 4], 5, [])\n" " ```\n" ). -spec last(zip_list(KFD)) -> zip_list(KFD). last(Zip_list) -> case lists:reverse(erlang:element(4, Zip_list)) of [] -> Zip_list; [Head | Tail] -> {zip_list, lists:append( erlang:element(2, Zip_list), [erlang:element(3, Zip_list) | lists:reverse(Tail)] ), Head, []} end. -file("src/zip_list.gleam", 242). ?DOC( " Move the cursor to the next element\n" " Returns `Error(Nil)` if there is no next element\n" "\n" " ## Examples\n" " ```gleam\n" " let numbers = new([1, 2], 3, [4, 5])\n" " next_try(numbers) == Ok(new([1, 2, 3], 4, [5]))\n" " ```\n" " ```gleam\n" " let numbers = new([1, 2, 3, 4, 5], 6, [])\n" " next_try(numbers) == Error(Nil)\n" " ```\n" ). -spec next_try(zip_list(KFJ)) -> {ok, zip_list(KFJ)} | {error, nil}. next_try(Zip_list) -> case erlang:element(4, Zip_list) of [] -> {error, nil}; [Head | Tail] -> {ok, {zip_list, lists:append( erlang:element(2, Zip_list), [erlang:element(3, Zip_list)] ), Head, Tail}} end. -file("src/zip_list.gleam", 223). ?DOC( " Move the cursor to the next element\n" " Returns the same ZipList if there is no next element\n" "\n" " ## Examples\n" " ```gleam\n" " let numbers = new([1, 2], 3, [4, 5])\n" " next(numbers) == new([1, 2, 3], 4, [5])\n" " ```\n" " ```gleam\n" " let numbers = new([1, 2, 3, 4, 5], 6, [])\n" " next(numbers) == new([1, 2, 3, 4, 5], 6, [])\n" " ```\n" ). -spec next(zip_list(KFG)) -> zip_list(KFG). next(Zip_list) -> case next_try(Zip_list) of {ok, New_zip_list} -> New_zip_list; {error, _} -> Zip_list end. -file("src/zip_list.gleam", 150). ?DOC( " Move the cursor N elements forward\n" "\n" " ## Examples\n" " ```gleam\n" " let numbers = new([1, 2], 3, [4, 5])\n" " forward(numbers, 2) == new([1, 2, 3, 4], 5, [])\n" " ```\n" " ```gleam\n" " let numbers = new([1, 2], 3, [4, 5])\n" " forward(numbers, 5) == new([1, 2, 3, 4, 5], 6, [])\n" " ```\n" ). -spec forward(zip_list(KEX), integer()) -> zip_list(KEX). forward(Zip_list, Times) -> gleam@bool:guard( erlang:element(4, Zip_list) =:= [], Zip_list, fun() -> case Times of 0 -> Zip_list; _ -> forward(next(Zip_list), Times - 1) end end ). -file("src/zip_list.gleam", 265). ?DOC( " Move the cursor to the next element, wrapping around to the first element if there is no next element\n" "\n" " ## Examples\n" " ```gleam\n" " let numbers = new([1, 2], 3, [4, 5])\n" " next_wrap(numbers) == new([1, 2, 3], 4, [5])\n" " ```\n" " ```gleam\n" " let numbers = new([1, 2, 3, 4, 5], 6, [])\n" " next_wrap(numbers) == new([], 1, [2, 3, 4, 5, 6])\n" " ```\n" ). -spec next_wrap(zip_list(KFO)) -> zip_list(KFO). next_wrap(Zip_list) -> case next_try(Zip_list) of {ok, New_zip_list} -> New_zip_list; {error, _} -> first(Zip_list) end. -file("src/zip_list.gleam", 303). ?DOC( " Move the cursor to the previous element\n" " Returns `Error(Nil)` if there is no previous element\n" "\n" " ## Examples\n" " ```gleam\n" " let numbers = new([1, 2], 3, [4, 5])\n" " previous_try(numbers) == Ok(new([1], 2, [3, 4, 5]))\n" " ```\n" " ```gleam\n" " let numbers = new([], 1, [2, 3, 4, 5])\n" " previous_try(numbers) == Error(Nil)\n" " ```\n" ). -spec previous_try(zip_list(KFU)) -> {ok, zip_list(KFU)} | {error, nil}. previous_try(Zip_list) -> Previous_reversed = lists:reverse(erlang:element(2, Zip_list)), case Previous_reversed of [] -> {error, nil}; [Head | Tail] -> {ok, {zip_list, lists:reverse(Tail), Head, [erlang:element(3, Zip_list) | erlang:element(4, Zip_list)]}} end. -file("src/zip_list.gleam", 284). ?DOC( " Move the cursor to the previous element\n" " Returns the same ZipList if there is no previous element\n" "\n" " ## Examples\n" " ```gleam\n" " let numbers = new([1, 2], 3, [4, 5])\n" " previous(numbers) == new([1], 2, [3, 4, 5])\n" " ```\n" " ```gleam\n" " let numbers = new([], 1, [2, 3, 4, 5])\n" " previous(numbers) == new([], 1, [2, 3, 4, 5])\n" " ```\n" ). -spec previous(zip_list(KFR)) -> zip_list(KFR). previous(Zip_list) -> case previous_try(Zip_list) of {ok, New_zip_list} -> New_zip_list; {error, _} -> Zip_list end. -file("src/zip_list.gleam", 107). ?DOC( " Move the cursor N elements backwards\n" "\n" " ## Examples\n" " ```gleam\n" " let numbers = new([1, 2], 3, [4, 5])\n" " backwards(numbers, 2) == new([], 1, [2, 3, 4, 5])\n" " ```\n" " ```gleam\n" " let numbers = new([1, 2], 3, [4, 5])\n" " backwards(numbers, 5) == new([], 1, [2, 3, 4, 5])\n" " ```\n" ). -spec backwards(zip_list(KER), integer()) -> zip_list(KER). backwards(Zip_list, Times) -> gleam@bool:guard( erlang:element(2, Zip_list) =:= [], Zip_list, fun() -> case Times of 0 -> Zip_list; _ -> backwards(previous(Zip_list), Times - 1) end end ). -file("src/zip_list.gleam", 329). ?DOC( " Move the cursor to the previous element, wrapping around to the last element if there is no previous element\n" "\n" " ## Examples\n" " ```gleam\n" " let numbers = new([1, 2], 3, [4, 5])\n" " previous_wrap(numbers) == new([1, 2, 3], 4, [5])\n" " ```\n" " ```gleam\n" " let numbers = new([], 1, [2, 3, 4, 5])\n" " previous_wrap(numbers) == new([1, 2, 3, 4], 5, [])\n" " ```\n" ). -spec previous_wrap(zip_list(KFZ)) -> zip_list(KFZ). previous_wrap(Zip_list) -> case previous_try(Zip_list) of {ok, New_zip_list} -> New_zip_list; {error, _} -> last(Zip_list) end. -file("src/zip_list.gleam", 345). ?DOC( " Append a list to the next elements of the ZipList\n" "\n" " ## Examples\n" " ```gleam\n" " let numbers = new([1, 2], 3, [4, 5])\n" " append_next(numbers, [6, 7]) == new([1, 2], 3, [4, 5, 6, 7])\n" " ```\n" ). -spec append_next(zip_list(KGC), list(KGC)) -> zip_list(KGC). append_next(Zip_list, Next) -> {zip_list, erlang:element(2, Zip_list), erlang:element(3, Zip_list), lists:append(erlang:element(4, Zip_list), Next)}. -file("src/zip_list.gleam", 360). ?DOC( " Append a list to the previous elements of the ZipList\n" "\n" " ## Examples\n" " ```gleam\n" " let numbers = new([1, 2], 3, [4, 5])\n" " append_previous(numbers, [-1, 0]) == new([1, 2, -1, 0], 3, [4, 5])\n" " ```\n" ). -spec append_previous(zip_list(KGG), list(KGG)) -> zip_list(KGG). append_previous(Zip_list, Previous) -> {zip_list, lists:append(erlang:element(2, Zip_list), Previous), erlang:element(3, Zip_list), erlang:element(4, Zip_list)}. -file("src/zip_list.gleam", 380). ?DOC( " Map a function over the elements of the ZipList, passing a flag indicating if the element is the current element\n" "\n" " ## Examples\n" " ```gleam\n" " let numbers = new([1, 2], 3, [4, 5])\n" " current_map(numbers, fn(x, is_current) {\n" " case is_current {\n" " True -> x * 10\n" " False -> x * 2\n" " }\n" " }) == new([2, 4], 30, [8, 10])\n" " ```\n" ). -spec current_map(zip_list(KGK), fun((KGK, boolean()) -> KGM)) -> zip_list(KGM). current_map(Zip_list, F) -> F_with_flag = fun(Element) -> F(Element, false) end, {zip_list, gleam@list:map(erlang:element(2, Zip_list), F_with_flag), F(erlang:element(3, Zip_list), true), gleam@list:map(erlang:element(4, Zip_list), F_with_flag)}. -file("src/zip_list.gleam", 405). ?DOC( " Filter the elements of the ZipList\n" "\n" " ## Examples\n" " ```gleam\n" " let numbers = new([1, 2], 3, [4, 5])\n" " filter(numbers, int.is_even) == new([2], 4, [])\n" " ```\n" " ```gleam\n" " let numbers = new([1, 2], 3, [4, 5])\n" " filter(numbers, int.is_odd) == new([1], 3, [5])\n" " ```\n" " ```gleam\n" " let numbers = new([], 1, [])\n" " filter(numbers, int.is_even) == Error(Nil)\n" " ```\n" ). -spec filter(zip_list(KGO), fun((KGO) -> boolean())) -> {ok, zip_list(KGO)} | {error, nil}. filter(Zip_list, F) -> Filtered_previous = gleam@list:filter(erlang:element(2, Zip_list), F), Filtered_next = gleam@list:filter(erlang:element(4, Zip_list), F), Filtered_current = case F(erlang:element(3, Zip_list)) of true -> {ok, erlang:element(3, Zip_list)}; false -> {error, nil} end, case Filtered_current of {ok, Current} -> {ok, {zip_list, Filtered_previous, Current, Filtered_next}}; {error, _} -> case {lists:reverse(Filtered_previous), Filtered_next} of {[], []} -> {error, nil}; {_, [Head | Tail]} -> {ok, {zip_list, Filtered_previous, Head, Tail}}; {[Head@1 | Tail@1], []} -> {ok, {zip_list, lists:reverse(Tail@1), Head@1, Filtered_next}} end end. -file("src/zip_list.gleam", 442). ?DOC( " Map a function over the elements of the ZipList, passing the index of each element\n" "\n" " ## Examples\n" " ```gleam\n" " let numbers = new([1, 2], 3, [4, 5])\n" " index_map(numbers, fn(x, i) { x * i }) == new([0, 2], 6, [12, 20])\n" " ```\n" ). -spec index_map(zip_list(KGT), fun((KGT, integer()) -> KGV)) -> zip_list(KGV). index_map(Zip_list, F) -> Previous_length = erlang:length(erlang:element(2, Zip_list)), {zip_list, gleam@list:index_map(erlang:element(2, Zip_list), F), F(erlang:element(3, Zip_list), Previous_length), gleam@list:index_map( erlang:element(4, Zip_list), fun(Element, Index) -> F(Element, (Index + Previous_length) + 1) end )}. -file("src/zip_list.gleam", 461). ?DOC( " Map a function over the elements of the ZipList\n" "\n" " ## Examples\n" " ```gleam\n" " let numbers = new([1, 2], 3, [4, 5])\n" " map(numbers, fn(x) { x * 2 }) == new([2, 4], 6, [8, 10])\n" " ```\n" ). -spec map(zip_list(KGX), fun((KGX) -> KGZ)) -> zip_list(KGZ). map(Zip_list, F) -> {zip_list, gleam@list:map(erlang:element(2, Zip_list), F), F(erlang:element(3, Zip_list)), gleam@list:map(erlang:element(4, Zip_list), F)}. -file("src/zip_list.gleam", 476). ?DOC( " Prepend a list to the next elements of the ZipList\n" "\n" " ## Examples\n" " ```gleam\n" " let numbers = new([1, 2], 3, [4, 5])\n" " prepend_next(numbers, [6, 7]) == new([1, 2], 3, [6, 7, 4, 5])\n" " ```\n" ). -spec prepend_next(zip_list(KHB), list(KHB)) -> zip_list(KHB). prepend_next(Zip_list, Next) -> {zip_list, erlang:element(2, Zip_list), erlang:element(3, Zip_list), lists:append(Next, erlang:element(4, Zip_list))}. -file("src/zip_list.gleam", 491). ?DOC( " Prepend a list to the previous elements of the ZipList\n" "\n" " ## Examples\n" " ```gleam\n" " let numbers = new([1, 2], 3, [4, 5])\n" " prepend_previous(numbers, [-1, 0]) == new([-1, 0, 1, 2], 3, [4, 5])\n" " ```\n" ). -spec prepend_previous(zip_list(KHF), list(KHF)) -> zip_list(KHF). prepend_previous(Zip_list, Previous) -> {zip_list, lists:append(Previous, erlang:element(2, Zip_list)), erlang:element(3, Zip_list), erlang:element(4, Zip_list)}. -file("src/zip_list.gleam", 563). ?DOC( " Remove the current element from the ZipList\n" " The cursor is moved to the next element if there is one, otherwise to the previous element\n" " Returns `Error(Nil)` if there is no next or previous element\n" "\n" " ## Examples\n" " ```gleam\n" " let numbers = new([1, 2], 3, [4, 5])\n" " remove_try(numbers) == Ok(new([1, 2], 4, [5]))\n" " ```\n" " ```gleam\n" " let numbers = new([1, 2], 3, [])\n" " remove_try(numbers) == Ok(new([1], 2, []))\n" " ```\n" " ```gleam\n" " let numbers = new([], 1, [])\n" " remove_try(numbers) == Error(Nil)\n" " ```\n" ). -spec remove_try(zip_list(KHP)) -> {ok, zip_list(KHP)} | {error, nil}. remove_try(Zip_list) -> case {erlang:element(4, Zip_list), lists:reverse(erlang:element(2, Zip_list))} of {[], []} -> {error, nil}; {[Head | Tail], _} -> {ok, {zip_list, erlang:element(2, Zip_list), Head, Tail}}; {_, [Head@1 | Tail@1]} -> {ok, {zip_list, lists:reverse(Tail@1), Head@1, erlang:element(4, Zip_list)}} end. -file("src/zip_list.gleam", 516). ?DOC( " Remove the current element from the ZipList\n" " The cursor is moved to the next element if there is one, otherwise to the previous element\n" " Returns the same ZipList if there is no next or previous element\n" "\n" " ## Examples\n" " ```gleam\n" " let numbers = new([1, 2], 3, [4, 5])\n" " remove(numbers) == new([1, 2], 4, [5])\n" " ```\n" " ```gleam\n" " let numbers = new([1, 2], 3, [])\n" " remove(numbers) == new([1], 2, [])\n" " ```\n" " ```gleam\n" " let numbers = new([], 1, [])\n" " remove(numbers) == new([], 1, [])\n" " ```\n" ). -spec remove(zip_list(KHJ)) -> zip_list(KHJ). remove(Zip_list) -> case remove_try(Zip_list) of {ok, New_zip_list} -> New_zip_list; {error, _} -> Zip_list end. -file("src/zip_list.gleam", 539). ?DOC( " Remove the current element from the ZipList\n" " The cursor is moved to the previous element if there is one, otherwise to the next element\n" "\n" " ## Examples\n" " ```gleam\n" " let numbers = new([1, 2], 3, [4, 5])\n" " remove_backwards(numbers) == new([1], 2, [3, 4, 5])\n" " ```\n" " ```gleam\n" " let numbers = new([], 1, [2, 3])\n" " remove_backwards(numbers) == new([], 2, [3])\n" " ```\n" " ```gleam\n" " let numbers = new([], 1, [])\n" " remove(numbers) == new([], 1, [])\n" " ```\n" ). -spec remove_backwards(zip_list(KHM)) -> zip_list(KHM). remove_backwards(Zip_list) -> case remove_try(Zip_list) of {ok, New_zip_list} -> previous(New_zip_list); {error, _} -> Zip_list end. -file("src/zip_list.gleam", 579). ?DOC( " Replace the current element of the ZipList\n" "\n" " ## Examples\n" " ```gleam\n" " let numbers = new([1, 2], 3, [4, 5])\n" " replace(numbers, 6) == new([1, 2], 6, [4, 5])\n" " ```\n" ). -spec replace(zip_list(KHU), KHU) -> zip_list(KHU). replace(Zip_list, New_current) -> {zip_list, erlang:element(2, Zip_list), New_current, erlang:element(4, Zip_list)}. -file("src/zip_list.gleam", 593). ?DOC( " Get the next elements of the ZipList\n" "\n" " ## Examples\n" " ```gleam\n" " new([1, 2], 3, [4, 5])\n" " |> get_all_next\n" " // => [4, 5]\n" " ```\n" ). -spec get_all_next(zip_list(KHX)) -> list(KHX). get_all_next(Zip_list) -> erlang:element(4, Zip_list). -file("src/zip_list.gleam", 605). ?DOC( " Get the previous elements of the ZipList\n" "\n" " ## Examples\n" " ```gleam\n" " new([1, 2], 3, [4, 5])\n" " |> get_all_previous\n" " // => [1, 2]\n" " ```\n" ). -spec get_all_previous(zip_list(KIA)) -> list(KIA). get_all_previous(Zip_list) -> erlang:element(2, Zip_list). -file("src/zip_list.gleam", 617). ?DOC( " Get the current element of the ZipList\n" "\n" " ## Examples\n" " ```gleam\n" " new([1, 2], 3, [4, 5])\n" " |> current\n" " // => 3\n" " ```\n" ). -spec current(zip_list(KID)) -> KID. current(Zip_list) -> erlang:element(3, Zip_list). -file("src/zip_list.gleam", 634). ?DOC( " Get the index of the current element in the ZipList\n" "\n" " ## Examples\n" " ```gleam\n" " new([1, 2], 3, [4, 5])\n" " |> index\n" " // => 2\n" " ```\n" " ```gleam\n" " new([], 3, [4, 5])\n" " |> index\n" " // => 0\n" " ```\n" ). -spec index(zip_list(any())) -> integer(). index(Zip_list) -> erlang:length(erlang:element(2, Zip_list)). -file("src/zip_list.gleam", 652). ?DOC( " Get the next element of the ZipList\n" " Returns `Error(Nil)` if there is no next element\n" "\n" " ## Examples\n" " ```gleam\n" " new([1, 2], 3, [4, 5])\n" " |> get_next\n" " // => Ok(4)\n" " ```\n" " ```gleam\n" " new([1, 2, 3], 4, [])\n" " |> get_next\n" " // => Error(Nil)\n" " ```\n" ). -spec get_next(zip_list(KIH)) -> {ok, KIH} | {error, nil}. get_next(Zip_list) -> case erlang:element(4, Zip_list) of [] -> {error, nil}; [Head | _] -> {ok, Head} end. -file("src/zip_list.gleam", 673). ?DOC( " Get the previous element of the ZipList\n" " Returns `Error(Nil)` if there is no previous element\n" "\n" " ## Examples\n" " ```gleam\n" " new([1, 2], 3, [4, 5])\n" " |> get_previous\n" " // => Ok(2)\n" " ```\n" " ```gleam\n" " new([], 3, [4, 5])\n" " |> get_previous\n" " // => Error(Nil)\n" " ```\n" ). -spec get_previous(zip_list(KIL)) -> {ok, KIL} | {error, nil}. get_previous(Zip_list) -> case lists:reverse(erlang:element(2, Zip_list)) of [] -> {error, nil}; [Head | _] -> {ok, Head} end. -file("src/zip_list.gleam", 693). ?DOC( " Check if the current element is the first element of the ZipList\n" "\n" " ## Examples\n" " ```gleam\n" " new([1, 2], 3, [4, 5])\n" " |> is_first\n" " // => False\n" " ```\n" " ```gleam\n" " new([], 3, [4, 5])\n" " |> is_first\n" " // => True\n" " ```\n" ). -spec is_first(zip_list(any())) -> boolean(). is_first(Zip_list) -> gleam@list:is_empty(erlang:element(2, Zip_list)). -file("src/zip_list.gleam", 710). ?DOC( " Check if the current element is the last element of the ZipList\n" "\n" " ## Examples\n" " ```gleam\n" " new([1, 2], 3, [4, 5])\n" " |> is_last\n" " // => False\n" " ```\n" " ```gleam\n" " new([1, 2], 3, [])\n" " |> is_last\n" " // => True\n" " ```\n" ). -spec is_last(zip_list(any())) -> boolean(). is_last(Zip_list) -> gleam@list:is_empty(erlang:element(4, Zip_list)). -file("src/zip_list.gleam", 722). ?DOC( " Get the length of the ZipList\n" "\n" " ## Examples\n" " ```gleam\n" " new([1, 2], 3, [4, 5])\n" " |> length\n" " // => 5\n" " ```\n" ). -spec length(zip_list(any())) -> integer(). length(Zip_list) -> (erlang:length(erlang:element(2, Zip_list)) + 1) + erlang:length( erlang:element(4, Zip_list) ).