Skip to content

Instantly share code, notes, and snippets.

@AleksLitynski
Last active August 29, 2015 14:07
Show Gist options
  • Save AleksLitynski/811b3510126baecb19e3 to your computer and use it in GitHub Desktop.
Save AleksLitynski/811b3510126baecb19e3 to your computer and use it in GitHub Desktop.
//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