summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Leopardi <an.leopardi@gmail.com>2018-05-11 01:05:14 +0200
committerAndrea Leopardi <an.leopardi@gmail.com>2018-05-11 01:05:14 +0200
commit5fd1476281022b0dc8631c23b8d1fb1061cf1c9f (patch)
tree363a3a0a5a1c3ef714c656440bba3bd3fd8f450c
parentdfabb6cc54443548d3148ffe2e0f8623d4eca3bc (diff)
downloadelixir-al/remove-access-get.tar.gz
Remove the Access.get/3 callbackal/remove-access-get
It was not being used. In fact, Access.get/3 was relying on the c:Access.fetch/2 callback for some reason.
-rw-r--r--lib/elixir/lib/access.ex56
-rw-r--r--lib/iex/test/iex/autocomplete_test.exs2
2 files changed, 3 insertions, 55 deletions
diff --git a/lib/elixir/lib/access.ex b/lib/elixir/lib/access.ex
index c9f5d16bd..3e2882174 100644
--- a/lib/elixir/lib/access.ex
+++ b/lib/elixir/lib/access.ex
@@ -182,28 +182,6 @@ defmodule Access do
@callback fetch(term :: t, key) :: {:ok, value} | :error
@doc """
- Invoked in order to access the value stored under `key` in the given term `term`,
- defaulting to `default` if not present.
-
- This function should return the value under `key` in `term` if there's
- such key, otherwise `default`.
-
- For most data structures, this can be implemented using `fetch/2` internally;
- for example:
-
- def get(structure, key, default) do
- case fetch(structure, key) do
- {:ok, value} -> value
- :error -> default
- end
- end
-
- See the `Map.get/3` and `Keyword.get/3` implementations for examples of
- how to implement this callback.
- """
- @callback get(term :: t, key, default :: value) :: value
-
- @doc """
Invoked in order to access the value under `key` and update it at the same time.
The implementation of this callback should invoke `fun` with the value under
@@ -329,43 +307,13 @@ defmodule Access do
"""
@spec get(container, term, term) :: term
@spec get(nil_container, any, default) :: default when default: var
- def get(container, key, default \\ nil)
-
- def get(%module{} = container, key, default) do
- try do
- module.fetch(container, key)
- rescue
- exception in UndefinedFunctionError ->
- raise_undefined_behaviour(exception, module, {^module, :fetch, [^container, ^key], _})
- else
+ def get(container, key, default \\ nil) do
+ case fetch(container, key) do
{:ok, value} -> value
:error -> default
end
end
- def get(map, key, default) when is_map(map) do
- case map do
- %{^key => value} -> value
- _ -> default
- end
- end
-
- def get(list, key, default) when is_list(list) and is_atom(key) do
- case :lists.keyfind(key, 1, list) do
- {_, value} -> value
- false -> default
- end
- end
-
- def get(list, key, _default) when is_list(list) do
- raise ArgumentError,
- "the Access calls for keywords expect the key to be an atom, got: " <> inspect(key)
- end
-
- def get(nil, _key, default) do
- default
- end
-
@doc """
Gets and updates the given key in a `container` (a map, a keyword list,
a struct that implements the `Access` behaviour).
diff --git a/lib/iex/test/iex/autocomplete_test.exs b/lib/iex/test/iex/autocomplete_test.exs
index 094bdaf49..8911fffa1 100644
--- a/lib/iex/test/iex/autocomplete_test.exs
+++ b/lib/iex/test/iex/autocomplete_test.exs
@@ -71,7 +71,7 @@ defmodule IEx.AutocompleteTest do
assert expand('b :strin') == {:yes, 'g', []}
assert expand('b String') == {:yes, '', ['String', 'StringIO']}
assert expand('b String.') == {:no, '', []}
- assert expand('b Access.') == {:yes, '', ['fetch/2', 'get/3', 'get_and_update/3', 'pop/2']}
+ assert expand('b Access.') == {:yes, '', ['fetch/2', 'get_and_update/3', 'pop/2']}
assert expand('b GenServer.term') == {:yes, 'inate', []}
assert expand('b GenServer.term') == {:yes, 'inate', []}
end