From: Siraaj Khandkar Date: Mon, 23 May 2016 18:22:58 +0000 (-0400) Subject: Use empty tuple as unit type, for all side-effects. X-Git-Tag: 4.0.0 X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=d1f395e36977ca0edf05e050c2c0a66daf953ccb;p=hope.git Use empty tuple as unit type, for all side-effects. --- diff --git a/src/hope.app.src b/src/hope.app.src index d36cc38..16745b5 100644 --- a/src/hope.app.src +++ b/src/hope.app.src @@ -1,7 +1,7 @@ {application, hope, [ {description, "Higher Order Programming in Erlang"}, - {vsn, "3.9.0"}, + {vsn, "4.0.0"}, {registered, []}, {applications, [ kernel, diff --git a/src/hope_gen_dictionary.erl b/src/hope_gen_dictionary.erl index 174ef67..c0b7e53 100644 --- a/src/hope_gen_dictionary.erl +++ b/src/hope_gen_dictionary.erl @@ -40,7 +40,7 @@ Acc. -callback iter(t(K, V), fun((K, V) -> any())) -> - ok. + {}. %% TODO: Decide if validation is to be done. If yes - wrap in hope_result:t/1 -callback of_kv_list([{K, V}]) -> diff --git a/src/hope_kv_list.erl b/src/hope_kv_list.erl index 44a78d4..6e3442d 100644 --- a/src/hope_kv_list.erl +++ b/src/hope_kv_list.erl @@ -106,10 +106,11 @@ pop(T1, K) -> end. -spec iter(t(K, V), fun((K, V) -> any())) -> - ok. + {}. iter(T, F1) -> F2 = lift_map(F1), - lists:foreach(F2, T). + ok = lists:foreach(F2, T), + {}. -spec map(t(K, V), fun((K, V) -> V)) -> t(K, V). diff --git a/src/hope_option.erl b/src/hope_option.erl index c645c53..29836f7 100644 --- a/src/hope_option.erl +++ b/src/hope_option.erl @@ -58,12 +58,12 @@ map({some, X}, F) -> {some, F(X)}; map(none , _) -> none. -spec iter(t(A), fun((A) -> (any()))) -> - ok. + {}. iter({some, X}, F) -> _ = F(X), - ok; + {}; iter(none, _) -> - ok. + {}. -spec pipe([fun((A) -> t(B))], A) -> t(B). diff --git a/test/hope_option_SUITE.erl b/test/hope_option_SUITE.erl index af1e12e..d2a73a3 100644 --- a/test/hope_option_SUITE.erl +++ b/test/hope_option_SUITE.erl @@ -66,12 +66,12 @@ t_map(_Cfg) -> t_iter(_Cfg) -> Key = key, - Put = fun (Val) -> _ = put(Key, Val), ok end, + Put = fun (Val) -> put(Key, Val) end, Get = fun () -> get(Key) end, Val = foo, - ok = hope_option:iter(none , Put), + {} = hope_option:iter(none , Put), undefined = Get(), - ok = hope_option:iter({some, Val}, Put), + {} = hope_option:iter({some, Val}, Put), Val = Get(). t_of_result(_Cfg) ->