Current section
Files
Jump to
Current section
Files
src/glearray.erl
-module(glearray).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([new/0, from_list/1, to_list/1, length/1, get/2, copy_set/3, copy_push/2, copy_insert/3]).
-export_type([array/1]).
-type array(FCW) :: any() | {gleam_phantom, FCW}.
-file("/home/luna/src/glearray/src/glearray.gleam", 32).
-spec new() -> array(any()).
new() ->
glearray_ffi:new().
-file("/home/luna/src/glearray/src/glearray.gleam", 38).
-spec from_list(list(FCZ)) -> array(FCZ).
from_list(List) ->
erlang:list_to_tuple(List).
-file("/home/luna/src/glearray/src/glearray.gleam", 44).
-spec to_list(array(FDC)) -> list(FDC).
to_list(Array) ->
erlang:tuple_to_list(Array).
-file("/home/luna/src/glearray/src/glearray.gleam", 66).
-spec length(array(any())) -> integer().
length(Array) ->
erlang:tuple_size(Array).
-file("/home/luna/src/glearray/src/glearray.gleam", 138).
-spec is_valid_index(array(any()), integer()) -> boolean().
is_valid_index(Array, Index) ->
(Index >= 0) andalso (Index < erlang:tuple_size(Array)).
-file("/home/luna/src/glearray/src/glearray.gleam", 89).
-spec get(array(FDH), integer()) -> {ok, FDH} | {error, nil}.
get(Array, Index) ->
case is_valid_index(Array, Index) of
true ->
{ok, glearray_ffi:get(Array, Index)};
false ->
{error, nil}
end.
-file("/home/luna/src/glearray/src/glearray.gleam", 123).
-spec copy_set(array(FDN), integer(), FDN) -> {ok, array(FDN)} | {error, nil}.
copy_set(Array, Index, Value) ->
case is_valid_index(Array, Index) of
true ->
{ok, glearray_ffi:set(Array, Index, Value)};
false ->
{error, nil}
end.
-file("/home/luna/src/glearray/src/glearray.gleam", 158).
-spec copy_push(array(FDX), FDX) -> array(FDX).
copy_push(Array, Value) ->
erlang:append_element(Array, Value).
-file("/home/luna/src/glearray/src/glearray.gleam", 197).
-spec copy_insert(array(FEA), integer(), FEA) -> {ok, array(FEA)} | {error, nil}.
copy_insert(Array, Index, Value) ->
case (Index >= 0) andalso (Index =< erlang:tuple_size(Array)) of
true ->
{ok, glearray_ffi:insert(Array, Index, Value)};
false ->
{error, nil}
end.