summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/struct/shr_attributes.erl10
-rw-r--r--src/shared/util/shr_lists_util.erl30
2 files changed, 36 insertions, 4 deletions
diff --git a/src/shared/struct/shr_attributes.erl b/src/shared/struct/shr_attributes.erl
index 44d2e04..7928862 100644
--- a/src/shared/struct/shr_attributes.erl
+++ b/src/shared/struct/shr_attributes.erl
@@ -98,11 +98,17 @@ mod_accuracy (Mod, Atts) ->
-spec mod_double_hit_chance (integer(), type()) -> type().
mod_double_hit_chance (Mod, Atts) ->
- Atts#attributes{ double_hit_chance = (Atts#attributes.double_hit_chance + Mod) }.
+ Atts#attributes
+ {
+ double_hit_chance = (Atts#attributes.double_hit_chance + Mod)
+ }.
-spec mod_critical_hit_chance (integer(), type()) -> type().
mod_critical_hit_chance (Mod, Atts) ->
- Atts#attributes{ critical_hit_chance = (Atts#attributes.critical_hit_chance + Mod) }.
+ Atts#attributes
+ {
+ critical_hit_chance = (Atts#attributes.critical_hit_chance + Mod)
+ }.
-spec mod_damage_modifier (integer(), type()) -> type().
mod_damage_modifier (Mod, Atts) ->
diff --git a/src/shared/util/shr_lists_util.erl b/src/shared/util/shr_lists_util.erl
index 0568692..348d002 100644
--- a/src/shared/util/shr_lists_util.erl
+++ b/src/shared/util/shr_lists_util.erl
@@ -11,13 +11,35 @@
[
%%% Gentoo hasn't marked Erlang/OTP 21 as stable yet, but I'd like to
%%% use this function.
- %%% TODO: remove once lists:search/2 is available.
- search/2
+ %%% TODO: remove once lists:search/2 is available.
+ search/2,
+ product/3
]
).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-spec product_internals
+ (
+ list(A),
+ list(B),
+ fun((A, B) -> C),
+ list(C)
+ )
+ -> list(C).
+product_internals ([], _ListB, _Fun, Result) ->
+ Result;
+product_internals ([A|Next], ListB, Fun, Result) ->
+ product_internals
+ (
+ Next,
+ ListB,
+ Fun,
+ (
+ lists:map(fun (B) -> Fun(A, B) end, ListB)
+ ++ Result
+ )
+ ).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -30,3 +52,7 @@ search (Pred, [Hd|Tail]) ->
end;
search (Pred, []) when is_function(Pred, 1) ->
false.
+
+-spec product (fun((A, B) -> C), list(A), list(B)) -> list(C).
+product (Fun, ListA, ListB) ->
+ product_internals(ListA, ListB, Fun, []).