Skip to content

Commit 40d11a5

Browse files
committed
iterator: rename Counter::new to count
to match the convention used by `range`, since `iterator::count` is already namespaced enough and won't be ambiguous
1 parent c13f4f3 commit 40d11a5

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

src/libextra/ringbuf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ mod tests {
696696
let u: ~[int] = deq.iter().transform(|&x| x).collect();
697697
assert_eq!(u, v);
698698

699-
let mut seq = iterator::Counter::new(0u, 2).take_(256);
699+
let mut seq = iterator::count(0u, 2).take_(256);
700700
let deq: RingBuf<uint> = seq.collect();
701701
for (i, &x) in deq.iter().enumerate() {
702702
assert_eq!(2*i, x);

src/libstd/iterator.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ pub trait IteratorUtil<A> {
313313
/// ~~~ {.rust}
314314
/// let xs = [2u, 3];
315315
/// let ys = [0u, 1, 0, 1, 2];
316-
/// let mut it = xs.iter().flat_map_(|&x| Counter::new(0u, 1).take_(x));
316+
/// let mut it = xs.iter().flat_map_(|&x| count(0u, 1).take_(x));
317317
/// // Check that `it` has the same elements as `ys`
318318
/// let mut i = 0;
319319
/// for x: uint in it {
@@ -351,7 +351,7 @@ pub trait IteratorUtil<A> {
351351
/// ~~~ {.rust}
352352
/// use std::iterator::Counter;
353353
///
354-
/// for i in Counter::new(0, 10) {
354+
/// for i in count(0, 10) {
355355
/// printfln!("%d", i);
356356
/// }
357357
/// ~~~
@@ -723,7 +723,7 @@ pub trait MultiplicativeIterator<A> {
723723
/// use std::iterator::Counter;
724724
///
725725
/// fn factorial(n: uint) -> uint {
726-
/// Counter::new(1u, 1).take_while(|&i| i <= n).product()
726+
/// count(1u, 1).take_while(|&i| i <= n).product()
727727
/// }
728728
/// assert!(factorial(0) == 1);
729729
/// assert!(factorial(1) == 1);
@@ -790,7 +790,7 @@ pub trait ClonableIterator {
790790
/// # Example
791791
///
792792
/// ~~~ {.rust}
793-
/// let a = Counter::new(1,1).take_(1);
793+
/// let a = count(1,1).take_(1);
794794
/// let mut cy = a.cycle();
795795
/// assert_eq!(cy.next(), Some(1));
796796
/// assert_eq!(cy.next(), Some(1));
@@ -1526,12 +1526,10 @@ pub struct Counter<A> {
15261526
step: A
15271527
}
15281528

1529-
impl<A> Counter<A> {
1530-
/// Creates a new counter with the specified start/step
1531-
#[inline]
1532-
pub fn new(start: A, step: A) -> Counter<A> {
1533-
Counter{state: start, step: step}
1534-
}
1529+
/// Creates a new counter with the specified start/step
1530+
#[inline]
1531+
pub fn count<A>(start: A, step: A) -> Counter<A> {
1532+
Counter{state: start, step: step}
15351533
}
15361534

15371535
/// A range of numbers from [0, N)
@@ -1618,7 +1616,7 @@ mod tests {
16181616

16191617
#[test]
16201618
fn test_counter_from_iter() {
1621-
let mut it = Counter::new(0, 5).take_(10);
1619+
let mut it = count(0, 5).take_(10);
16221620
let xs: ~[int] = FromIterator::from_iterator(&mut it);
16231621
assert_eq!(xs, ~[0, 5, 10, 15, 20, 25, 30, 35, 40, 45]);
16241622
}
@@ -1636,7 +1634,7 @@ mod tests {
16361634
}
16371635
assert_eq!(i, expected.len());
16381636

1639-
let ys = Counter::new(30u, 10).take_(4);
1637+
let ys = count(30u, 10).take_(4);
16401638
let mut it = xs.iter().transform(|&x| x).chain_(ys);
16411639
let mut i = 0;
16421640
for x in it {
@@ -1648,7 +1646,7 @@ mod tests {
16481646

16491647
#[test]
16501648
fn test_filter_map() {
1651-
let mut it = Counter::new(0u, 1u).take_(10)
1649+
let mut it = count(0u, 1u).take_(10)
16521650
.filter_map(|x| if x.is_even() { Some(x*x) } else { None });
16531651
assert_eq!(it.collect::<~[uint]>(), ~[0*0, 2*2, 4*4, 6*6, 8*8]);
16541652
}
@@ -1737,7 +1735,7 @@ mod tests {
17371735
fn test_iterator_flat_map() {
17381736
let xs = [0u, 3, 6];
17391737
let ys = [0u, 1, 2, 3, 4, 5, 6, 7, 8];
1740-
let mut it = xs.iter().flat_map_(|&x| Counter::new(x, 1).take_(3));
1738+
let mut it = xs.iter().flat_map_(|&x| count(x, 1).take_(3));
17411739
let mut i = 0;
17421740
for x in it {
17431741
assert_eq!(x, ys[i]);
@@ -1784,13 +1782,13 @@ mod tests {
17841782
#[test]
17851783
fn test_cycle() {
17861784
let cycle_len = 3;
1787-
let it = Counter::new(0u, 1).take_(cycle_len).cycle();
1785+
let it = count(0u, 1).take_(cycle_len).cycle();
17881786
assert_eq!(it.size_hint(), (uint::max_value, None));
17891787
for (i, x) in it.take_(100).enumerate() {
17901788
assert_eq!(i % cycle_len, x);
17911789
}
17921790

1793-
let mut it = Counter::new(0u, 1).take_(0).cycle();
1791+
let mut it = count(0u, 1).take_(0).cycle();
17941792
assert_eq!(it.size_hint(), (0, Some(0)));
17951793
assert_eq!(it.next(), None);
17961794
}
@@ -1852,7 +1850,7 @@ mod tests {
18521850

18531851
#[test]
18541852
fn test_iterator_size_hint() {
1855-
let c = Counter::new(0, 1);
1853+
let c = count(0, 1);
18561854
let v = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
18571855
let v2 = &[10, 11, 12];
18581856
let vi = v.iter();

0 commit comments

Comments
 (0)