Has anyone ever wondered why this notation is not a common thing?
100.loop();
Or to be more specific:
100.loop(i => Debug.Log(i));
Currently this can be done with an extension method.
static class IntExt{
public static void loop(this int arg, System.Action<int> callback){
for(int i = 0; i < arg; i++){
callback(i);
}
}
}
Even though int is a primitive type, it can be extended to have “methods”.
You can also chain those.
int a = ...;
return a.min(b).min(c).min(d).max(e);
Now, you probably shouldn’t do that in production, because the idea is uncommon, and therefore breaches principle of least astonishment, but. I sorta wonder, why this isn’t a common thing somewhere.
Although I did encounter Bjarne Stroutstroup’s proposal to equal methods and functions.
Thoughts?