diff options
| author | Paul Stansifer <paul.stansifer@gmail.com> | 2012-07-20 15:33:18 -0700 |
|---|---|---|
| committer | Paul Stansifer <paul.stansifer@gmail.com> | 2012-07-24 11:44:58 -0700 |
| commit | 1c472564e37567dda820062cfd117115113b9def (patch) | |
| tree | 06f475b12e937ab09febd74a27361da02ec8b87d /src/libcore/uint-template.rs | |
| parent | a57686d46d1fbdb3a8c6aec6761ff4791e6a9526 (diff) | |
Add `5.timesi() |idx| { ... }`
Diffstat (limited to 'src/libcore/uint-template.rs')
| -rw-r--r-- | src/libcore/uint-template.rs | 15 |
1 files changed, 14 insertions, 1 deletions
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<T> { parse_buf(str::bytes(s), 10u) } |
