2012-04-11 23:45:18 -05:00
|
|
|
// This makes use of a clever hack that brson came up with to
|
|
|
|
// workaround our lack of traits and lack of macros. See core.{rc,rs} for
|
|
|
|
// how this file is used.
|
|
|
|
|
|
|
|
import inst::{IMPL_T, EACH, SIZE_HINT};
|
|
|
|
export extensions;
|
|
|
|
|
2012-08-07 20:10:06 -05:00
|
|
|
impl<A> IMPL_T<A>: iter::base_iter<A> {
|
2012-04-11 23:45:18 -05:00
|
|
|
fn each(blk: fn(A) -> bool) { EACH(self, blk) }
|
|
|
|
fn size_hint() -> option<uint> { SIZE_HINT(self) }
|
2012-07-11 17:00:40 -05:00
|
|
|
}
|
|
|
|
|
2012-08-07 20:10:06 -05:00
|
|
|
impl<A> IMPL_T<A>: iter::extended_iter<A> {
|
2012-04-11 23:45:18 -05:00
|
|
|
fn eachi(blk: fn(uint, A) -> bool) { iter::eachi(self, blk) }
|
|
|
|
fn all(blk: fn(A) -> bool) -> bool { iter::all(self, blk) }
|
|
|
|
fn any(blk: fn(A) -> bool) -> bool { iter::any(self, blk) }
|
|
|
|
fn foldl<B>(+b0: B, blk: fn(B, A) -> B) -> B {
|
|
|
|
iter::foldl(self, b0, blk)
|
|
|
|
}
|
|
|
|
fn contains(x: A) -> bool { iter::contains(self, x) }
|
|
|
|
fn count(x: A) -> uint { iter::count(self, x) }
|
2012-06-25 17:04:00 -05:00
|
|
|
fn position(f: fn(A) -> bool) -> option<uint> {
|
|
|
|
iter::position(self, f)
|
|
|
|
}
|
2012-04-11 23:45:18 -05:00
|
|
|
}
|
|
|
|
|
2012-08-07 20:10:06 -05:00
|
|
|
impl<A: copy> IMPL_T<A>: iter::copyable_iter<A> {
|
2012-06-29 18:26:56 -05:00
|
|
|
fn filter_to_vec(pred: fn(A) -> bool) -> ~[A] {
|
2012-04-11 23:45:18 -05:00
|
|
|
iter::filter_to_vec(self, pred)
|
|
|
|
}
|
2012-06-29 18:26:56 -05:00
|
|
|
fn map_to_vec<B>(op: fn(A) -> B) -> ~[B] { iter::map_to_vec(self, op) }
|
|
|
|
fn to_vec() -> ~[A] { iter::to_vec(self) }
|
2012-04-11 23:45:18 -05:00
|
|
|
|
2012-06-14 19:57:22 -05:00
|
|
|
// FIXME--bug in resolve prevents this from working (#2611)
|
2012-06-29 18:26:56 -05:00
|
|
|
// fn flat_map_to_vec<B:copy,IB:base_iter<B>>(op: fn(A) -> IB) -> ~[B] {
|
2012-04-11 23:45:18 -05:00
|
|
|
// iter::flat_map_to_vec(self, op)
|
|
|
|
// }
|
|
|
|
|
|
|
|
fn min() -> A { iter::min(self) }
|
|
|
|
fn max() -> A { iter::max(self) }
|
2012-07-05 20:01:11 -05:00
|
|
|
|
|
|
|
fn find(p: fn(A) -> bool) -> option<A> {
|
|
|
|
for self.each |i| {
|
2012-08-01 19:30:05 -05:00
|
|
|
if p(i) { return some(i) }
|
2012-07-05 20:01:11 -05:00
|
|
|
}
|
2012-08-01 19:30:05 -05:00
|
|
|
return none;
|
2012-07-05 20:01:11 -05:00
|
|
|
}
|
2012-04-11 23:45:18 -05:00
|
|
|
}
|