home
/
code
/
hope.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
e0fbc1d
)
Add has_key/2 dictionary method.
3.6.0
author
Siraaj Khandkar
<siraaj@khandkar.net>
Wed, 1 Jul 2015 18:37:54 +0000
(14:37 -0400)
committer
Siraaj Khandkar
<siraaj@khandkar.net>
Wed, 1 Jul 2015 18:37:54 +0000
(14:37 -0400)
src/hope.app.src
patch
|
blob
|
blame
|
history
src/hope_gen_dictionary.erl
patch
|
blob
|
blame
|
history
src/hope_kv_list.erl
patch
|
blob
|
blame
|
history
test/hope_dictionary_SUITE.erl
patch
|
blob
|
blame
|
history
diff --git
a/src/hope.app.src
b/src/hope.app.src
index
98c9de0
..
d2b376c
100644
(file)
--- a/
src/hope.app.src
+++ b/
src/hope.app.src
@@
-1,7
+1,7
@@
{application, hope,
[
{description, "Higher Order Programming in Erlang"},
{application, hope,
[
{description, "Higher Order Programming in Erlang"},
- {vsn, "3.
5
.0"},
+ {vsn, "3.
6
.0"},
{registered, []},
{applications, [
kernel,
{registered, []},
{applications, [
kernel,
diff --git
a/src/hope_gen_dictionary.erl
b/src/hope_gen_dictionary.erl
index
1fab838
..
ea0f551
100644
(file)
--- a/
src/hope_gen_dictionary.erl
+++ b/
src/hope_gen_dictionary.erl
@@
-48,3
+48,6
@@
-callback to_kv_list(t(K, V)) ->
[{K, V}].
-callback to_kv_list(t(K, V)) ->
[{K, V}].
+
+-callback has_key(t(K, _), K) ->
+ boolean().
diff --git
a/src/hope_kv_list.erl
b/src/hope_kv_list.erl
index
cb1c4a4
..
c12f3b4
100644
(file)
--- a/
src/hope_kv_list.erl
+++ b/
src/hope_kv_list.erl
@@
-25,6
+25,7
@@
, fold/3
, of_kv_list/1
, to_kv_list/1
, fold/3
, of_kv_list/1
, to_kv_list/1
+ , has_key/2
, find_unique_presence_violations/2 % No optional keys
, find_unique_presence_violations/3 % Specify optional keys
, validate_unique_presence/2 % No optional keys
, find_unique_presence_violations/2 % No optional keys
, find_unique_presence_violations/3 % Specify optional keys
, validate_unique_presence/2 % No optional keys
@@
-206,6
+207,10
@@
presence_violations_to_list(#hope_kv_list_presence_violations
end,
ErrorDups ++ ErrorMissing ++ ErrorUnsupported.
end,
ErrorDups ++ ErrorMissing ++ ErrorUnsupported.
+-spec has_key(t(K, _), K) ->
+ boolean().
+has_key(T, K1) ->
+ lists:any(fun ({K2, _}) -> K1 =:= K2 end, T).
%% ============================================================================
%% Helpers
%% ============================================================================
%% Helpers
diff --git
a/test/hope_dictionary_SUITE.erl
b/test/hope_dictionary_SUITE.erl
index
04e40d3
..
cf0bfba
100644
(file)
--- a/
test/hope_dictionary_SUITE.erl
+++ b/
test/hope_dictionary_SUITE.erl
@@
-16,6
+16,7
@@
, t_pop/1
, t_fold/1
, t_dictionary_specs/1
, t_pop/1
, t_fold/1
, t_dictionary_specs/1
+ , t_has_key/1
]).
]).
@@
-38,6
+39,7
@@
groups() ->
, t_pop
, t_fold
, t_dictionary_specs
, t_pop
, t_fold
, t_dictionary_specs
+ , t_has_key
],
Properties = [parallel],
[{?DICT_MODULE_KV_LIST, Properties, Tests}].
],
Properties = [parallel],
[{?DICT_MODULE_KV_LIST, Properties, Tests}].
@@
-107,3
+109,13
@@
t_fold(Cfg) ->
t_dictionary_specs(Cfg) ->
{some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE),
[] = proper:check_specs(DictModule).
t_dictionary_specs(Cfg) ->
{some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE),
[] = proper:check_specs(DictModule).
+
+t_has_key(Cfg) ->
+ {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE),
+ D = DictModule:of_kv_list([{a, 1}, {b, 2}, {c, 3}]),
+ true = DictModule:has_key(D, a),
+ true = DictModule:has_key(D, b),
+ true = DictModule:has_key(D, c),
+ false = DictModule:has_key(D, d),
+ false = DictModule:has_key(D, e),
+ false = DictModule:has_key(D, f).
This page took
0.026391 seconds
and
4
git commands to generate.