/
hcr_model.erl.v2
38 lines (29 loc) · 1.07 KB
/
hcr_model.erl.v2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
-compile({parse_transform, hcr_accessors}).
-module(hcr_model).
-include("hcr.hrl").
-export([new/1, perform_action/1]).
-export_type([property/0]).
-type property() :: {v1, non_neg_integer()} |
{v2, non_neg_integer()}.
?ATTR_ACCESSOR([ {v1, 0}
, {v2, 0}
]).
%% represent model as tagged proplist, to able to have
%% somewhat useful -specs and make sure we are dealing
%% with the right model in the accessors
-spec new(hcr_config:type()) -> model().
new(Type) -> Model = {?MODULE, Type, []}.
-spec perform_action(model()) -> model().
perform_action({?MODULE, _, _} = Model) ->
Fs = [ fun (M) -> v1(M, v1(M) + hcr_config:incr1(M)) end
, fun (M) -> v2(M, v2(M) + hcr_config:incr2(M)) end
],
lists:foldl(fun (F, M) -> F(M) end, Model, Fs).
%% ===================================================================
%% Accessors
%% ===================================================================
%% ... auto-generated by parse-transform like this
%% -export([v1/1, v1/2]).
%% v1(M) -> ...
%% v1(M, V) -> ...
%% ...