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:
c50166f
)
Add get with default to dictionary interface.
2.1.0
author
Siraaj Khandkar
<siraaj@khandkar.net>
Sun, 25 Jan 2015 02:14:50 +0000
(21:14 -0500)
committer
Siraaj Khandkar
<siraaj@khandkar.net>
Sun, 25 Jan 2015 02:14:50 +0000
(21:14 -0500)
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
051e619
..
3de6e3d
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, "2.
0.1
"},
+ {vsn, "2.
1.0
"},
{registered, []},
{applications, [
kernel,
{registered, []},
{applications, [
kernel,
diff --git
a/src/hope_gen_dictionary.erl
b/src/hope_gen_dictionary.erl
index
0d45ecd
..
dda6eb0
100644
(file)
--- a/
src/hope_gen_dictionary.erl
+++ b/
src/hope_gen_dictionary.erl
@@
-15,6
+15,9
@@
-callback get(t(K, V), K) ->
hope_option:t(V).
-callback get(t(K, V), K) ->
hope_option:t(V).
+-callback get(t(K, V), K, V) ->
+ V.
+
-callback set(t(K, V), K, V) ->
t(K, V).
-callback set(t(K, V), K, V) ->
t(K, V).
diff --git
a/src/hope_kv_list.erl
b/src/hope_kv_list.erl
index
be11c31
..
d9a8177
100644
(file)
--- a/
src/hope_kv_list.erl
+++ b/
src/hope_kv_list.erl
@@
-12,6
+12,7
@@
-export(
[ empty/0
, get/2
-export(
[ empty/0
, get/2
+ , get/3
, set/3
, update/3
, pop/2
, set/3
, update/3
, pop/2
@@
-53,6
+54,12
@@
get(T, K) ->
; {K, V} -> {some, V}
end.
; {K, V} -> {some, V}
end.
+-spec get(t(K, V), K, V) ->
+ V.
+get(T, K, Default) ->
+ Vopt = get(T, K),
+ hope_option:get(Vopt, Default).
+
-spec set(t(K, V), K, V) ->
t(K, V).
set(T, K, V) ->
-spec set(t(K, V), K, V) ->
t(K, V).
set(T, K, V) ->
diff --git
a/test/hope_dictionary_SUITE.erl
b/test/hope_dictionary_SUITE.erl
index
914ae48
..
4f355ca
100644
(file)
--- a/
test/hope_dictionary_SUITE.erl
+++ b/
test/hope_dictionary_SUITE.erl
@@
-1,7
+1,5
@@
-module(hope_dictionary_SUITE).
-module(hope_dictionary_SUITE).
--include_lib("proper/include/proper.hrl").
-
%% Callbacks
-export(
[ all/0
%% Callbacks
-export(
[ all/0
@@
-14,6
+12,7
@@
-export(
[ t_set_new/1
, t_set_existing/1
-export(
[ t_set_new/1
, t_set_existing/1
+ , t_get/1
, t_pop/1
, t_fold/1
, t_dictionary_specs/1
, t_pop/1
, t_fold/1
, t_dictionary_specs/1
@@
-35,6
+34,7
@@
groups() ->
Tests =
[ t_set_new
, t_set_existing
Tests =
[ t_set_new
, t_set_existing
+ , t_get
, t_pop
, t_fold
, t_dictionary_specs
, t_pop
, t_fold
, t_dictionary_specs
@@
-53,6
+53,18
@@
end_per_group(_DictModule, _Cfg) ->
%% Test cases
%% =============================================================================
%% Test cases
%% =============================================================================
+t_get(Cfg) ->
+ {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE),
+ K1 = k1,
+ K2 = k2,
+ V1 = v1,
+ V2 = v2,
+ D = DictModule:set(DictModule:empty(), K1, V1),
+ {some, V1} = DictModule:get(D, K1),
+ V1 = DictModule:get(D, K1, V2),
+ none = DictModule:get(D, K2),
+ V2 = DictModule:get(D, K2, V2).
+
t_set_new(Cfg) ->
{some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE),
Key = key,
t_set_new(Cfg) ->
{some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE),
Key = key,
This page took
0.032309 seconds
and
4
git commands to generate.