diff --git a/lib/array.ex b/lib/array.ex index 4fc9639..b6f46cd 100644 --- a/lib/array.ex +++ b/lib/array.ex @@ -11,15 +11,6 @@ defmodule Array do @type opt :: {:fixed, boolean} | :fixed | {:default, any} | {:size, non_neg_integer} | non_neg_integer @type orddict :: [{index, element}] - @doc """ - Creates a new, extendible array with initial size zero. - The default value is the atom nil, not undefined. - """ - @spec new() :: t - def new() do - %Array{content: :array.new({:default, nil})} - end - @doc """ Creates a new fixed array according to the given options. By default, the array is extendible and has initial size zero. @@ -38,7 +29,7 @@ defmodule Array do * Sets the default value for the array to `value`. """ @spec new(opts) :: t - def new(options) do + def new(options \\ []) do if is_list(options) do %Array{content: :array.new([{:default, nil} | options])} else @@ -103,13 +94,6 @@ defmodule Array do def foldr(%Array{content: c}, acc, fun), do: :array.foldr(fun, acc, c) - @doc """ - Equivalent to `from_list(list, nil)`. - """ - @spec from_list(list) :: t - def from_list(list), - do: %Array{content: :array.from_list(list, nil)} - @doc """ Converts a list to an extendible array. `default` is used as the value for uninitialized entries of the array. @@ -117,16 +101,9 @@ defmodule Array do If `list` is not a proper list, the call raises `ArgumentError`. """ @spec from_list(list, any) :: t - def from_list(list, default), + def from_list(list, default \\ nil), do: %Array{content: :array.from_list(list, default)} - @doc """ - Equivalent to `from_orddict(orddict, nil)`. - """ - @spec from_orddict(orddict) :: t - def from_orddict(orddict), - do: %Array{content: :array.from_orddict(orddict, nil)} - @doc """ Converts an ordered list of pairs `{index, value}` to a corresponding extendible array. `default` is used as the value for uninitialized entries of the array. @@ -135,7 +112,7 @@ defmodule Array do the call raises `ArgumentError`. """ @spec from_orddict(orddict, any) :: t - def from_orddict(orddict, default), + def from_orddict(orddict, default \\ nil), do: %Array{content: :array.from_orddict(orddict, default)} @doc """