From 1c472564e37567dda820062cfd117115113b9def Mon Sep 17 00:00:00 2001 From: Paul Stansifer Date: Fri, 20 Jul 2012 15:33:18 -0700 Subject: Add `5.timesi() |idx| { ... }` --- src/libcore/uint-template.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/libcore/uint-template.rs') diff --git a/src/libcore/uint-template.rs b/src/libcore/uint-template.rs index 4f35f1a8756..e3b4f08ddaa 100644 --- a/src/libcore/uint-template.rs +++ b/src/libcore/uint-template.rs @@ -11,7 +11,7 @@ export range; export compl; export to_str, to_str_bytes; export from_str, from_str_radix, str, parse_buf; -export num, ord, eq, times; +export num, ord, eq, times, timesi; const min_value: T = 0 as T; const max_value: T = 0 as T - 1 as T; @@ -120,6 +120,19 @@ impl times of iter::times for T { } } +impl timesi of iter::timesi for T { + #[inline(always)] + /// Like `times`, but with an index, `eachi`-style. + fn timesi(it: fn(uint) -> bool) { + let slf = self as uint; + let mut i = 0u; + while i < slf { + if !it(i) { break } + i += 1u; + } + } +} + /// Parse a string to an int fn from_str(s: ~str) -> option { parse_buf(str::bytes(s), 10u) } -- cgit 1.4.1-3-g733a5