Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::marker::PhantomData;
- trait NewIterator {
- type Item;
- fn next(&mut self) -> Option<Self::Item>;
- }
- fn map<I,F,T,R>(i:I, f:F)
- -> impl NewIterator<Item=R>
- where I: NewIterator<Item=T>,
- F: FnMut(T) -> R
- {
- struct Map<I,F,R>{ i:I, f:F, p:PhantomData<R> };
- impl<I,F,T,R> NewIterator for Map<I,F,R>
- where I: NewIterator<Item=T>,
- F: FnMut(T) -> R
- {
- type Item = R;
- fn next(&mut self) -> Option<R> {
- match self.i.next() {
- Some(t) => Some((self.f)(t)),
- None => None
- }
- }
- }
- Map{i:i, f:f, p:PhantomData}
- }
- fn main(){
- }
Add Comment
Please, Sign In to add comment