Last active
August 29, 2015 14:07
-
-
Save AleksLitynski/811b3510126baecb19e3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//A list of effects to be applied to a value | |
List<Func<double,double>> effects = new List<Func<double,double>>(); | |
//Two sample anonymous effects. | |
effects.Add(initial_value => initial_value / 2); | |
effects.Add(initial_value => initial_value - 1); | |
//Storing an effect as a function, then applying it. | |
Func<double,double> fire_effect = x => x*x; | |
effects.Add(effect); | |
//An initial value for the stat | |
double initial_value = 10; | |
//itterate over the effects and return the final stat. | |
double compute_value(double init_val, List<Func<double,double>> effect_list){ | |
foreach (Func<double,double> effect in effect_list) | |
{ | |
init_val = effect(init_val); | |
} | |
return init_val; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment