You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
742 B
35 lines
742 B
//! Extensions
|
|
use super::*;
|
|
use std::{
|
|
iter::{self, Fuse,}
|
|
};
|
|
pub trait TaekTwoExt: Iterator
|
|
{
|
|
fn take_two(self) -> TakeTwo<Self>;
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct TakeTwo<I: ?Sized + Iterator>(I);
|
|
|
|
impl<T, I: Iterator<Item=T> + ?Sized> Iterator for TakeTwo<I>
|
|
{
|
|
type Item = (T, Option<T>);
|
|
#[inline]
|
|
fn next(&mut self) -> Option<Self::Item>
|
|
{
|
|
let first = self.0.next()?;
|
|
Some((first, self.0.next()))
|
|
}
|
|
}
|
|
|
|
impl<I: Iterator> TaekTwoExt for I
|
|
where I: Iterator + Sized
|
|
{
|
|
#[inline]
|
|
fn take_two(self) -> TakeTwo<Self> {
|
|
TakeTwo(self)
|
|
}
|
|
}
|
|
|
|
//TODO: XXX: Copy all other iterator `ext` traits like `Collection: Extend<T>, U: Into<T>` (e.g. `String` with `char`) joining and such from older projects
|