I hate seeing stray for loops, but there are two areas where they still seem necessary, despite using Link.
A) When you are deleting something:
for (...) {
if (condition) { array.splice(i, 1); i--; }
}
B) When you are computing something.
for (var i = 0; i < 12; ++i) {
DrawText(0, 16 * i);
}
Case B can be mitigated using lists of items and iterating over them, but I can still create generators for Link to mitigate these cases where you are doing a raw loop 'n' times.
But, most importantly A was counter-intuitive to Link. But I don't think that has to be the case.
Introducing: RemoveI leverage the Link chain and make an end-element such that whatever values survive until the end, can get gobbled up. I think the implementation can be improved upon, but I do utilize a neat trick. I walk the line backwards when removing elements, this works since the indices I receive from Link are in sorted order.
Now you can do this:
var a = [1, 2, 3, 0, 4, 5, 8, 9, 7, 0];
Link(a).where(even).remove();
a; // [1, 3, 4, 8, 0]
I'm still testing the code, and I'll push it later today. Maybe I can make it faster? But ultimately it's going to make it easier to remove things, such that human induced error goes down.
BTW, this caused me to do it:
mini.Delegate.prototype.remove = function(o, method)
{
for (var i = 0; i < this.invokeList.length; ++i) {
if (o == this.invokeList[i].o && method == this.invokeList[i].method) {
this.invokeList.splice(i, 1);
break;
}
}
};
Imagine writing:
mini.Delegate.prototype.remove = function(o, method)
{
mini.Link(this.invokeList).where(function(item) { return o == item.o && method == item.method; }).remove();
};
Wait... I just realized now that you intended to remove the first item it sees (hence the break), well we can now do that with the new functional parameter for .indexOf:
mini.Delegate.prototype.remove = function(o, method)
{
var index = mini.Link(this.invokeList).indexOf(function(item, i) { return o == item.o && method == item.method; });
if (index >= 0) this.invokeList.splice(index, 1);
};
But that's good for one at a time, whereas now you can do lists of removals (which ought to be faster than looking up indices each time).