#![feature(associated_types)]
#![feature(unboxed_closures)]
#![feature(macro_rules)]
#![crate_name="itertools"]
#![crate_type="dylib"]
pub use adaptors::{
Interleave,
Product,
PutBack,
FnMap,
Dedup,
Batching,
GroupBy,
Step,
};
pub use intersperse::Intersperse;
pub use islice::{ISlice};
pub use map::MapMut;
pub use rciter::RcIter;
pub use stride::Stride;
pub use stride::StrideMut;
pub use tee::Tee;
pub use times::Times;
pub use times::times;
pub use linspace::{linspace, Linspace};
pub use zip::{ZipLongest, EitherOrBoth};
pub use ziptuple::Zip;
mod adaptors;
mod intersperse;
mod islice;
mod linspace;
mod map;
pub mod misc;
mod rciter;
mod stride;
mod tee;
mod times;
mod zip;
mod ziptuple;
#[macro_export]
pub macro_rules! iproduct(
($I:expr) => (
($I)
);
($I:expr, $J:expr $(, $K:expr)*) => (
{
let it = ::itertools::Product::new($I, $J);
$(
let it = ::itertools::misc::FlatTuples::new(::itertools::Product::new(it, $K));
)*
it
}
);
);
#[deprecated="izip!() is deprecated, use Zip::new instead"]
#[macro_export]
pub macro_rules! izip(
($I:expr) => (
($I)
);
($I:expr, $J:expr $(, $K:expr)*) => (
{
::itertools::Zip::new(($I, $J $(, $K)*))
}
);
);
#[macro_export]
pub macro_rules! icompr(
($r:expr for $x:pat in $J:expr if $pred:expr) => (
($J).filter_map(|$x| if $pred { Some($r) } else { None })
);
($r:expr for $x:pat in $J:expr) => (
($J).filter_map(|$x| Some($r))
);
);
pub trait Itertools : Iterator + Sized {
#[deprecated="Use libstd .map() instead"]
fn fn_map<B>(self, map: fn(<Self as Iterator>::Item) -> B) -> FnMap< <Self as Iterator>::Item, B, Self> {
FnMap::new(self, map)
}
#[deprecated="Use libstd .map() instead"]
fn map_unboxed<B, F: FnMut(<Self as Iterator>::Item) -> B>(self, map: F) -> MapMut<F, Self> {
MapMut::new(self, map)
}
fn interleave<J: Iterator<Item=<Self as Iterator>::Item>>(self, other: J) -> Interleave<Self, J> {
Interleave::new(self, other)
}
fn intersperse(self, element: <Self as Iterator>::Item) -> Intersperse< <Self as Iterator>::Item, Self> {
Intersperse::new(self, element)
}
#[inline]
fn zip_longest<U: Iterator>(self, other: U) -> ZipLongest<Self, U> {
ZipLongest::new(self, other)
}
fn dedup(self) -> Dedup< <Self as Iterator>::Item, Self> {
Dedup::new(self)
}
fn batching<B, F: FnMut(&mut Self) -> Option<B>>(self, f: F) -> Batching<Self, F> {
Batching::new(self, f)
}
fn group_by<K, F: FnMut(& <Self as Iterator>::Item) -> K>(self, key: F) -> GroupBy< <Self as Iterator>::Item, K, Self, F>
{
GroupBy::new(self, key)
}
fn tee(self) -> (Tee< <Self as Iterator>::Item, Self>, Tee< <Self as Iterator>::Item, Self>)
{
tee::new(self)
}
fn slice<R: misc::GenericRange>(self, range: R) -> ISlice<Self>
{
ISlice::new(self, range)
}
fn into_rc(self) -> RcIter<Self>
{
RcIter::new(self)
}
fn step(self, n: uint) -> Step<Self>
{
Step::new(self, n)
}
fn find_position<P>(&mut self, mut pred: P) -> Option<(uint, <Self as Iterator>::Item)>
where P: FnMut(&<Self as Iterator>::Item) -> bool
{
for (index, elt) in self.by_ref().enumerate() {
if pred(&elt) {
return Some((index, elt))
}
}
None
}
fn dropn(&mut self, mut n: uint) -> uint {
let start = n;
while n > 0 {
match self.next() {
Some(..) => n -= 1,
None => break
}
}
start - n
}
fn dropping(mut self, n: uint) -> Self {
self.dropn(n);
self
}
fn drain(&mut self) {
for _ in *self { }
}
fn apply<F: FnMut(<Self as Iterator>::Item)>(&mut self, mut f: F) {
for elt in *self { f(elt) }
}
fn collect_vec(self) -> Vec< <Self as Iterator>::Item>
{
self.collect()
}
}
impl<T: Iterator> Itertools for T { }
#[inline]
pub fn write<'a, A: 'a, I: Iterator<Item=&'a mut A>, J: Iterator<Item=A>>
(mut to: I, mut from: J) -> uint
{
let mut count = 0u;
for elt in from {
match to.next() {
None => break,
Some(ptr) => *ptr = elt
}
count += 1;
}
count
}