Skip to content

Commit b44f423

Browse files
author
blake2-ppc
committed
std::iterator: Rename .peek() to .inspect()
1 parent 8b9e1ce commit b44f423

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

src/libstd/iterator.rs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,15 @@ pub trait Iterator<A> {
286286
///let xs = [1u, 4, 2, 3, 8, 9, 6];
287287
///let sum = xs.iter()
288288
/// .map(|&x| x)
289-
/// .peek(|&x| debug!("filtering %u", x))
289+
/// .inspect(|&x| debug!("filtering %u", x))
290290
/// .filter(|&x| x % 2 == 0)
291-
/// .peek(|&x| debug!("%u made it through", x))
291+
/// .inspect(|&x| debug!("%u made it through", x))
292292
/// .sum();
293293
///println(sum.to_str());
294294
/// ~~~
295295
#[inline]
296-
fn peek<'r>(self, f: &'r fn(&A)) -> Peek<'r, A, Self> {
297-
Peek{iter: self, f: f}
296+
fn inspect<'r>(self, f: &'r fn(&A)) -> Inspect<'r, A, Self> {
297+
Inspect{iter: self, f: f}
298298
}
299299

300300
/// An adaptation of an external iterator to the for-loop protocol of rust.
@@ -1329,14 +1329,14 @@ impl<'self,
13291329

13301330
/// An iterator that calls a function with a reference to each
13311331
/// element before yielding it.
1332-
pub struct Peek<'self, A, T> {
1332+
pub struct Inspect<'self, A, T> {
13331333
priv iter: T,
13341334
priv f: &'self fn(&A)
13351335
}
13361336

1337-
impl<'self, A, T> Peek<'self, A, T> {
1337+
impl<'self, A, T> Inspect<'self, A, T> {
13381338
#[inline]
1339-
fn do_peek(&self, elt: Option<A>) -> Option<A> {
1339+
fn do_inspect(&self, elt: Option<A>) -> Option<A> {
13401340
match elt {
13411341
Some(ref a) => (self.f)(a),
13421342
None => ()
@@ -1346,11 +1346,11 @@ impl<'self, A, T> Peek<'self, A, T> {
13461346
}
13471347
}
13481348

1349-
impl<'self, A, T: Iterator<A>> Iterator<A> for Peek<'self, A, T> {
1349+
impl<'self, A, T: Iterator<A>> Iterator<A> for Inspect<'self, A, T> {
13501350
#[inline]
13511351
fn next(&mut self) -> Option<A> {
13521352
let next = self.iter.next();
1353-
self.do_peek(next)
1353+
self.do_inspect(next)
13541354
}
13551355

13561356
#[inline]
@@ -1359,23 +1359,25 @@ impl<'self, A, T: Iterator<A>> Iterator<A> for Peek<'self, A, T> {
13591359
}
13601360
}
13611361

1362-
impl<'self, A, T: DoubleEndedIterator<A>> DoubleEndedIterator<A> for Peek<'self, A, T> {
1362+
impl<'self, A, T: DoubleEndedIterator<A>> DoubleEndedIterator<A>
1363+
for Inspect<'self, A, T> {
13631364
#[inline]
13641365
fn next_back(&mut self) -> Option<A> {
13651366
let next = self.iter.next_back();
1366-
self.do_peek(next)
1367+
self.do_inspect(next)
13671368
}
13681369
}
13691370

1370-
impl<'self, A, T: RandomAccessIterator<A>> RandomAccessIterator<A> for Peek<'self, A, T> {
1371+
impl<'self, A, T: RandomAccessIterator<A>> RandomAccessIterator<A>
1372+
for Inspect<'self, A, T> {
13711373
#[inline]
13721374
fn indexable(&self) -> uint {
13731375
self.iter.indexable()
13741376
}
13751377

13761378
#[inline]
13771379
fn idx(&self, index: uint) -> Option<A> {
1378-
self.do_peek(self.iter.idx(index))
1380+
self.do_inspect(self.iter.idx(index))
13791381
}
13801382
}
13811383

@@ -1651,13 +1653,13 @@ mod tests {
16511653
}
16521654

16531655
#[test]
1654-
fn test_peek() {
1656+
fn test_inspect() {
16551657
let xs = [1u, 2, 3, 4];
16561658
let mut n = 0;
16571659

16581660
let ys = xs.iter()
16591661
.map(|&x| x)
1660-
.peek(|_| n += 1)
1662+
.inspect(|_| n += 1)
16611663
.collect::<~[uint]>();
16621664

16631665
assert_eq!(n, xs.len());
@@ -2011,11 +2013,11 @@ mod tests {
20112013
}
20122014

20132015
#[test]
2014-
fn test_random_access_peek() {
2016+
fn test_random_access_inspect() {
20152017
let xs = [1, 2, 3, 4, 5];
20162018

2017-
// test .map and .peek that don't implement Clone
2018-
let it = xs.iter().peek(|_| {});
2019+
// test .map and .inspect that don't implement Clone
2020+
let it = xs.iter().inspect(|_| {});
20192021
assert_eq!(xs.len(), it.indexable());
20202022
for (i, elt) in xs.iter().enumerate() {
20212023
assert_eq!(Some(elt), it.idx(i));
@@ -2027,7 +2029,6 @@ mod tests {
20272029
fn test_random_access_map() {
20282030
let xs = [1, 2, 3, 4, 5];
20292031

2030-
// test .map and .peek that don't implement Clone
20312032
let it = xs.iter().map(|x| *x);
20322033
assert_eq!(xs.len(), it.indexable());
20332034
for (i, elt) in xs.iter().enumerate() {

0 commit comments

Comments
 (0)