From 99fd18ae3aa61238700208a5f2b2959c1b1a2d80 Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Wed, 22 Apr 2015 12:23:14 -0400 Subject: [PATCH] Return k/v list itself from validate_unique_presence. Being that the main use-case is as part of a pipeline that manipulates said k/v list. --- src/hope.app.src | 2 +- src/hope_kv_list.erl | 10 ++++++---- test/hope_kv_list_SUITE.erl | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/hope.app.src b/src/hope.app.src index b16a643..9d0ece1 100644 --- a/src/hope.app.src +++ b/src/hope.app.src @@ -1,7 +1,7 @@ {application, hope, [ {description, "Higher Order Programming in Erlang"}, - {vsn, "2.5.0"}, + {vsn, "3.0.0"}, {registered, []}, {applications, [ kernel, diff --git a/src/hope_kv_list.erl b/src/hope_kv_list.erl index 2000098..7b25797 100644 --- a/src/hope_kv_list.erl +++ b/src/hope_kv_list.erl @@ -131,14 +131,16 @@ of_kv_list(List) -> % TODO: Decide if validation is to be done here. Do so if yes. List. --spec validate_unique_presence(t(K, _V), [K]) -> - hope_result:t(ok, [presence_error(K)]). +-spec validate_unique_presence(T, [K]) -> + hope_result:t(T, [presence_error(K)]) + when T :: t(K, _V). validate_unique_presence(T, KeysRequired) -> KeysOptional = [], validate_unique_presence(T, KeysRequired, KeysOptional). -spec validate_unique_presence(t(K, _V), [K], [K]) -> - hope_result:t(ok, [presence_error(K)]). + hope_result:t(T, [presence_error(K)]) + when T :: t(K, _V). validate_unique_presence(T, KeysRequired, KeysOptional) -> case find_unique_presence_violations(T, KeysRequired, KeysOptional) of #hope_kv_list_presence_violations @@ -146,7 +148,7 @@ validate_unique_presence(T, KeysRequired, KeysOptional) -> , keys_duplicated = [] , keys_unsupported = [] } -> - {ok, ok} + {ok, T} ; #hope_kv_list_presence_violations{}=Violations -> {error, presence_violations_to_list(Violations)} end. diff --git a/test/hope_kv_list_SUITE.erl b/test/hope_kv_list_SUITE.erl index 3ae5290..b986039 100644 --- a/test/hope_kv_list_SUITE.erl +++ b/test/hope_kv_list_SUITE.erl @@ -43,7 +43,7 @@ t_validate_unique_presence(_Cfg) -> DictDups = [{a, 1}, {b, 2}, {c, 3}, {a, 4}], DictMissing = [{a, 1}, {b, 2}], - {ok, ok} = + {ok, DictOk} = hope_kv_list:validate_unique_presence(DictOk, KeysRequired), #hope_kv_list_presence_violations { keys_missing = [] -- 2.20.1