Guest User

Untitled

a guest
May 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. use std::marker::PhantomData;
  2.  
  3. trait NewIterator {
  4. type Item;
  5. fn next(&mut self) -> Option<Self::Item>;
  6. }
  7. fn map<I,F,T,R>(i:I, f:F)
  8. -> impl NewIterator<Item=R>
  9. where I: NewIterator<Item=T>,
  10. F: FnMut(T) -> R
  11. {
  12. struct Map<I,F,R>{ i:I, f:F, p:PhantomData<R> };
  13. impl<I,F,T,R> NewIterator for Map<I,F,R>
  14. where I: NewIterator<Item=T>,
  15. F: FnMut(T) -> R
  16. {
  17. type Item = R;
  18. fn next(&mut self) -> Option<R> {
  19. match self.i.next() {
  20. Some(t) => Some((self.f)(t)),
  21. None => None
  22. }
  23. }
  24. }
  25. Map{i:i, f:f, p:PhantomData}
  26. }
  27.  
  28.  
  29. fn main(){
  30.  
  31. }
Add Comment
Please, Sign In to add comment