On 9/29/11 11:00 AM, Graydon Hoare wrote:
- Write >1 iter interfaces on most collections, with varying
strategies, to reduce unwanted boilerplate in cases you don't
need it. Cold code is cold, harmless.
vec::each(v) == takes fn(e) -> (), returns ()
vec::scan(v) == takes fn(e) -> bool, returns ()
vec::find(v) == takes fn(e) -> bool, returns option::t<e>
I really, really think the exterior-iterator style is wrong. It puts
logic in the wrong place, encourages hand-recoding loop logic
incorrectly rather than collecting a rich library of correct
enumerators. You can write a whole lot of cold enumerators that are safe
and do-interesting-things to cover, I think, any of the needs of an
external-iterator. This was less true when we had no closures, but now
that we have block closures, I don't think there's any excuse.
Given that we clearly need more discussion here before we reach
consensus, I'd like to propose doing the above for 0.1, and removing
iters as they currently stand. I already added vec::eachi and it's
pretty nice to use -- the added sugar in |for each| doesn't seem to buy
us much.
I whipped up a small testcase using clang and it seems that LLVM indeed
can optimize this style of iteration into a loop.
Is everyone ok with this?
Patrick
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev