Download:
parent 53:eab83bab5659
54:2e633dc02528 default tip
Anton Shestakov <engored@ya.ru>, Sat, 08 Mar 2014 23:46:38 +0900
Strictly speaking, rps_rules has no state.

1 файлов изменено, 6 вставок(+), 6 удалений(-) [+]
src/rps_rules.erl file | annotate | diff | comparison | revisions
--- a/src/rps_rules.erl Sat Mar 08 23:45:03 2014 +0900
+++ b/src/rps_rules.erl Sat Mar 08 23:46:38 2014 +0900
@@ -29,20 +29,20 @@
% rock, paper, paper -> paper
% rock, rock, paper -> paper
-winning_hand(Hands, State=#ruleinfo{}) ->
+winning_hand(Hands, Ruleinfo=#ruleinfo{}) ->
HSet = sets:from_list(Hands),
sets:fold(
fun(Hand, Acc) ->
- Loses = dict:fetch(Hand, State#ruleinfo.loses),
+ Loses = dict:fetch(Hand, Ruleinfo#ruleinfo.loses),
case sets:is_disjoint(sets:from_list(Loses), HSet) of
false -> Acc;
true -> Hand
end
end, undefined, HSet).
-why(H1, H2, State=#ruleinfo{}) when is_atom(H2) ->
- atom_to_list(dict:fetch({H1, H2}, State#ruleinfo.why));
+why(H1, H2, Ruleinfo=#ruleinfo{}) when is_atom(H2) ->
+ atom_to_list(dict:fetch({H1, H2}, Ruleinfo#ruleinfo.why));
-why(H1, Hands, State=#ruleinfo{}) when is_list(Hands) ->
- F = fun(H2) -> why(H1, H2, State) ++ " " ++ atom_to_list(H2) end,
+why(H1, Hands, Ruleinfo=#ruleinfo{}) when is_list(Hands) ->
+ F = fun(H2) -> why(H1, H2, Ruleinfo) ++ " " ++ atom_to_list(H2) end,
atom_to_list(H1) ++ " " ++ string:join(lists:map(F, Hands), ", ").