[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [sc-users] detect / detectIndex
Will there ever be a parallel to detect and detectIndex that will
start at a user-supplied index? Any reason the current methods
couldn't be modified to do this?
It's a pain... if I want to start at the beginning of a collection,
fine, but otherwise I have to write the while loop myself. Waste of
effort.
hjh
I'd also suggest to always hand in a starting index, like in Order-detect
but this cannot be implemented in Collection (as Collection is not
indexeable necessarily.) So SequenceableCollection-detect should
probably be:
+SequenceableCollection {
detect { | function, offset=0 |
var size, elem;
size = this.size;
while {
offset < size
} {
elem = this[offset];
if (function.value(elem, offset)) { ^elem };
offset = offset + 1
};
^nil
}
detectIndex { | function, offset=0 |
var size, elem;
size = this.size;
while {
offset < size
} {
elem = this[offset];
if (function.value(elem, offset)) { ^offset };
offset = offset + 1
};
^nil
}
}
--
.