Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

39 lines (29 sloc) 1.1 kb
-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) -> ...
%% ...
Jump to Line
Something went wrong with that request. Please try again.