Skip to content

Commit a2b9813

Browse files
committed
repea iter: make map last work
1 parent ef21257 commit a2b9813

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

library/core/src/iter/adapters/map.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ where
112112
self.iter.size_hint()
113113
}
114114

115+
fn last(mut self) -> Option<Self::Item>
116+
where
117+
Self: Sized,
118+
{
119+
self.iter.last().map(&mut self.f)
120+
}
121+
115122
fn try_fold<Acc, G, R>(&mut self, init: Acc, g: G) -> R
116123
where
117124
Self: Sized,

library/coretests/tests/iter/sources.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ fn test_repeat_last() {
4141
assert_eq!(repeat(42).last(), Some(42));
4242
}
4343

44+
#[test]
45+
fn test_repeat_map_double_last() {
46+
assert_eq!(repeat(42).map(|e| 2 * e).last(), Some(2 * 42));
47+
}
48+
4449
#[test]
4550
fn test_repeat_with() {
4651
#[derive(PartialEq, Debug)]

0 commit comments

Comments
 (0)